All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] file: Fix file descriptor leak in copy_fd_bitmaps()
@ 2022-03-26 11:40 Fedor Pchelkin
  2022-03-26 14:17 ` Alexey Khoroshilov
  0 siblings, 1 reply; 20+ messages in thread
From: Fedor Pchelkin @ 2022-03-26 11:40 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Fedor Pchelkin, linux-fsdevel, linux-kernel, Alexey Khoroshilov

If count argument in copy_fd_bitmaps() is not a multiple of
BITS_PER_BYTE, then one byte is lost and is not used in further
manipulations with cpy value in memcpy() and memset()
causing a leak. The leak was introduced with close_range() call
using CLOSE_RANGE_UNSHARE flag.

The patch suggests implementing an indicator (named add_byte)
of count being multiple of BITS_PER_BYTE and adding it to the
cpy value.

Found by Syzkaller (https://github.com/google/syzkaller).

Signed-off-by: Fedor Pchelkin <aissur0002@gmail.com>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 fs/file.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 3ef1479df203..3c64a6423604 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -56,10 +56,8 @@ static void copy_fd_bitmaps(struct fdtable *nfdt, struct fdtable *ofdt,
 {
 	unsigned int cpy, set;
 	unsigned int add_byte = 0;
-	
 	if (count % BITS_PER_BYTE != 0)
 		add_byte = 1;
-	
 	cpy = count / BITS_PER_BYTE + add_byte;
 	set = (nfdt->max_fds - count) / BITS_PER_BYTE;
 	memcpy(nfdt->open_fds, ofdt->open_fds, cpy);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-03-30  7:47 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-26 11:40 [PATCH 4/4] file: Fix file descriptor leak in copy_fd_bitmaps() Fedor Pchelkin
2022-03-26 14:17 ` Alexey Khoroshilov
2022-03-26 22:15   ` Linus Torvalds
2022-03-26 22:37     ` Linus Torvalds
2022-03-27 21:54       ` aissur0002
2022-03-27 22:21         ` Linus Torvalds
2022-03-29 10:23           ` Christian Brauner
2022-03-29 14:40             ` Christian Brauner
2022-03-29 21:28               ` Linus Torvalds
2022-03-29 20:44           ` aissur0002
2022-03-29 21:02             ` Linus Torvalds
2022-03-29 22:18               ` Linus Torvalds
2022-03-29 22:23                 ` Linus Torvalds
2022-03-30  7:47                   ` Christian Brauner
2022-03-30  5:21                 ` Jason A. Donenfeld
2022-03-30  6:08                   ` Linus Torvalds
2022-03-30  6:21                     ` Jason A. Donenfeld
2022-03-30  6:28                       ` Linus Torvalds
2022-03-30  6:43                         ` Linus Torvalds
2022-03-29 23:02           ` Alexey Khoroshilov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.