From: Kees Cook <keescook@chromium.org>
To: "Dr. David Alan Gilbert" <linux@treblig.org>
Cc: Dave Kleikamp <shaggy@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] jfs: Use unsigned variable for length calculations
Date: Mon, 6 Feb 2023 10:35:21 -0800 [thread overview]
Message-ID: <63e1486a.050a0220.7001.ca15@mx.google.com> (raw)
In-Reply-To: <Y96/SUlPUl7xH1NO@gallifrey>
On Sat, Feb 04, 2023 at 08:25:45PM +0000, Dr. David Alan Gilbert wrote:
> * Kees Cook (keescook@chromium.org) wrote:
> > To avoid confusing the compiler about possible negative sizes, switch
> > "ssize" which can never be negative from int to u32. Seen with GCC 13:
> >
> > ../fs/jfs/namei.c: In function 'jfs_symlink': ../include/linux/fortify-string.h:57:33: warning: '__builtin_memcpy' pointer overflow between offset 0 and size [-2147483648, -1]
> > [-Warray-bounds=]
> > 57 | #define __underlying_memcpy __builtin_memcpy
> > | ^
> > ...
> > ../fs/jfs/namei.c:950:17: note: in expansion of macro 'memcpy'
> > 950 | memcpy(ip->i_link, name, ssize);
> > | ^~~~~~
> >
> > Cc: Dave Kleikamp <shaggy@kernel.org>
> > Cc: Christian Brauner <brauner@kernel.org>
> > Cc: Dave Chinner <dchinner@redhat.com>
> > Cc: jfs-discussion@lists.sourceforge.net
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > fs/jfs/namei.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
> > index b29d68b5eec5..494b9f4043cf 100644
> > --- a/fs/jfs/namei.c
> > +++ b/fs/jfs/namei.c
> > @@ -876,7 +876,7 @@ static int jfs_symlink(struct mnt_idmap *idmap, struct inode *dip,
> > tid_t tid;
> > ino_t ino = 0;
> > struct component_name dname;
> > - int ssize; /* source pathname size */
> > + u32 ssize; /* source pathname size */
>
> Had you considered using size_t - this is set from a strlen and used by a memcpy
> that both talk size_t.
I considered that, but I've had other maintainers upset about doubling
the variable size. I opted to keep the variable 32-bit here, so the
machine code would only change to lose signed-ness.
-Kees
--
Kees Cook
next prev parent reply other threads:[~2023-02-06 18:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-04 18:33 [PATCH] jfs: Use unsigned variable for length calculations Kees Cook
2023-02-04 20:25 ` Dr. David Alan Gilbert
2023-02-06 18:35 ` Kees Cook [this message]
2023-02-06 19:50 ` Dr. David Alan Gilbert
2023-06-01 16:55 ` Kees Cook
2023-06-02 5:28 ` Jeff Xu
2023-06-05 13:24 ` David Laight
2023-06-02 8:32 ` Christian Brauner
2023-06-02 13:37 ` Dave Kleikamp
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=63e1486a.050a0220.7001.ca15@mx.google.com \
--to=keescook@chromium.org \
--cc=brauner@kernel.org \
--cc=dchinner@redhat.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@treblig.org \
--cc=shaggy@kernel.org \
/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