mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexey Khoroshilov <khoroshilov@ispras.ru>
To: Fedor Pchelkin <aissur0002@gmail.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 4/4] file: Fix file descriptor leak in copy_fd_bitmaps()
Date: Sat, 26 Mar 2022 17:17:32 +0300	[thread overview]
Message-ID: <c7fcaccf-7ac0-fae8-3f41-d6552b689a70@ispras.ru> (raw)
In-Reply-To: <20220326114009.1690-1-aissur0002@gmail.com>

Looks like bfp has a set of macro suitable for such cases:

#define BITS_PER_BYTE_MASKED(bits) ((bits) & BITS_PER_BYTE_MASK)
#define BITS_ROUNDDOWN_BYTES(bits) ((bits) >> 3)
#define BITS_ROUNDUP_BYTES(bits) \
	(BITS_ROUNDDOWN_BYTES(bits) + !!BITS_PER_BYTE_MASKED(bits))

May be it makes sense to move them to a generic header and to use here?

--
Alexey Khoroshilov


On 26.03.2022 14:40, Fedor Pchelkin wrote:
> 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);
> 


  reply	other threads:[~2022-03-26 14:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-26 11:40 Fedor Pchelkin
2022-03-26 14:17 ` Alexey Khoroshilov [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7fcaccf-7ac0-fae8-3f41-d6552b689a70@ispras.ru \
    --to=khoroshilov@ispras.ru \
    --cc=aissur0002@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®