loop: reject binding to procfs and sysfs files#910
Conversation
|
Upstream branch: 8fde5d1 |
3f4a345 to
c6dc343
Compare
|
Upstream branch: e43ffb6 |
7f7bcc5 to
262663f
Compare
c6dc343 to
fc36596
Compare
|
Upstream branch: ba3e43a |
262663f to
fcfe5d2
Compare
fc36596 to
7bed9c3
Compare
|
Upstream branch: ddd664b |
fcfe5d2 to
69995fa
Compare
7bed9c3 to
a7bb5c5
Compare
|
Upstream branch: 979c294 |
69995fa to
571d345
Compare
a7bb5c5 to
5e41a3b
Compare
|
Upstream branch: acb7500 |
571d345 to
26e348e
Compare
5e41a3b to
c3a084b
Compare
|
Upstream branch: 9716c08 |
26e348e to
9f9323e
Compare
c3a084b to
5f78e5d
Compare
|
Upstream branch: 2a2974b |
9f9323e to
2f1a4ef
Compare
5f78e5d to
e48f9db
Compare
|
Upstream branch: 062871f |
2f1a4ef to
c620e94
Compare
199644a to
e6d9eb8
Compare
|
Upstream branch: 66affa3 |
c620e94 to
b432ad6
Compare
e6d9eb8 to
7d8604f
Compare
I noticed that /dev/loopX accepts pseudo files, for loop_validate_file()
currently only checks:
if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
return -EINVAL;
and pseudo files are treated as S_ISREG().
Reading from pseudo files via /dev/loopX causes unexpected results, as it
tries to repeatedly read the entire content up to the size visible to the
"ls" command (padded with repeating data).
# ls -l /sys/power/pm_test
-rw-r--r-- 1 root root 4096 May 26 22:14 /sys/power/pm_test
# cat /sys/power/pm_test | wc
1 6 48
# cat $(losetup -f --show /sys/power/pm_test) | wc
85 513 4096
Writing to pseudo files via /dev/loopX might also cause undesirable
results. Therefore, explicitly reject binding to pseudo files on procfs
and sysfs for now. Other filesystems can be appended as needed.
There is another intention for this change. Currently, we are evaluating
the possibility of calling drain_workqueue() from __loop_clr_fd() in order
to address a NULL pointer dereference in lo_rw_aio() [1].
However, introducing drain_workqueue() into the loop teardown path where
disk->open_mutex is held forms a circular locking dependency when a pseudo
file that takes a global lock is specified as the backing store for the
loop device.
If drain_workqueue() is called from __loop_clr_fd(), an example of a
circular locking dependency that involves system_transition_mutex and
disk->open_mutex can be triggered by the following reproduction steps:
# echo 7:0 > /sys/power/resume
# losetup /dev/loop0 /sys/power/resume
# cat /dev/loop0 > /dev/null
# losetup -d /dev/loop0
Even if our final solution for [1] does not call drain_workqueue() with
disk->open_mutex held, rejecting binding to pseudo files that confuse
userspace programs is a standalone improvement.
Link: https://syzkaller.appspot.com/bug?extid=cd8a9a308e879a4e2c28 [1]
Analyzed-by: AI Mode in Google Search (no mail address)
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
|
Upstream branch: bade58e |
b432ad6 to
3370523
Compare
Pull request for series with
subject: loop: reject binding to procfs and sysfs files
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1103283