Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

debugfs: Return error during {full/open}_proxy_open() on rmmod

If a kernel module gets unloaded then it printed report about a leak before
commit 275678e7a9be ("debugfs: Check module state before warning in
{full/open}_proxy_open()"). An additional check was added in this commit to
avoid this printing. But it was forgotten that the function must return an
error in this case because it was not actually opened.

As result, the systems started to crash or to hang when a module was
unloaded while something was trying to open a file.

Fixes: 275678e7a9be ("debugfs: Check module state before warning in {full/open}_proxy_open()")
Cc: Taehee Yoo <ap420073@gmail.com>
Reported-by: Mário Lopes <ml@simonwunderlich.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Link: https://lore.kernel.org/r/20210802162444.7848-1-sven@narfation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sven Eckelmann and committed by
Greg Kroah-Hartman
112cedc8 fac58b4a

+6 -2
+6 -2
fs/debugfs/file.c
··· 179 179 if (!fops_get(real_fops)) { 180 180 #ifdef CONFIG_MODULES 181 181 if (real_fops->owner && 182 - real_fops->owner->state == MODULE_STATE_GOING) 182 + real_fops->owner->state == MODULE_STATE_GOING) { 183 + r = -ENXIO; 183 184 goto out; 185 + } 184 186 #endif 185 187 186 188 /* Huh? Module did not clean up after itself at exit? */ ··· 316 314 if (!fops_get(real_fops)) { 317 315 #ifdef CONFIG_MODULES 318 316 if (real_fops->owner && 319 - real_fops->owner->state == MODULE_STATE_GOING) 317 + real_fops->owner->state == MODULE_STATE_GOING) { 318 + r = -ENXIO; 320 319 goto out; 320 + } 321 321 #endif 322 322 323 323 /* Huh? Module did not cleanup after itself at exit? */