]> git.baikalelectronics.ru Git - kernel.git/commit
pipe: Fix missing lock in pipe_resize_ring()
authorDavid Howells <dhowells@redhat.com>
Thu, 26 May 2022 06:34:52 +0000 (07:34 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 27 May 2022 17:45:59 +0000 (10:45 -0700)
commitd08ca8294b7e5b121c09b44d27ce2536502ea8ce
tree6efe4119c78622c4d198e3c0dc2501d9a239ff73
parent6c8f41576f560ea849c689dd90287eea8c9ef03e
pipe: Fix missing lock in pipe_resize_ring()

pipe_resize_ring() needs to take the pipe->rd_wait.lock spinlock to
prevent post_one_notification() from trying to insert into the ring
whilst the ring is being replaced.

The occupancy check must be done after the lock is taken, and the lock
must be taken after the new ring is allocated.

The bug can lead to an oops looking something like:

 BUG: KASAN: use-after-free in post_one_notification.isra.0+0x62e/0x840
 Read of size 4 at addr ffff88801cc72a70 by task poc/27196
 ...
 Call Trace:
  post_one_notification.isra.0+0x62e/0x840
  __post_watch_notification+0x3b7/0x650
  key_create_or_update+0xb8b/0xd20
  __do_sys_add_key+0x175/0x340
  __x64_sys_add_key+0xbe/0x140
  do_syscall_64+0x5c/0xc0
  entry_SYSCALL_64_after_hwframe+0x44/0xae

Reported by Selim Enes Karaduman @Enesdex working with Trend Micro Zero
Day Initiative.

Fixes: 175295c8c9fa ("pipe: Add general notification queue support")
Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17291
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/pipe.c