linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] hfsplus: Fix out-of-bounds warnings in __hfsplus_setxattr
Date: Wed, 31 Mar 2021 05:53:57 +0100	[thread overview]
Message-ID: <20210331045357.GV351017@casper.infradead.org> (raw)
In-Reply-To: <20210330214320.93600506530f1ab18338b467@linux-foundation.org>

On Tue, Mar 30, 2021 at 09:43:20PM -0700, Andrew Morton wrote:
> On Tue, 30 Mar 2021 09:52:26 -0500 "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
> 
> > Fix the following out-of-bounds warnings by enclosing
> > structure members file and finder into new struct info:
> > 
> > fs/hfsplus/xattr.c:300:5: warning: 'memcpy' offset [65, 80] from the object at 'entry' is out of the bounds of referenced subobject 'user_info' with type 'struct DInfo' at offset 48 [-Warray-bounds]
> > fs/hfsplus/xattr.c:313:5: warning: 'memcpy' offset [65, 80] from the object at 'entry' is out of the bounds of referenced subobject 'user_info' with type 'struct FInfo' at offset 48 [-Warray-bounds]
> > 
> > Refactor the code by making it more "structured."
> > 
> > Also, this helps with the ongoing efforts to enable -Warray-bounds and
> > makes the code clearer and avoid confusing the compiler.
> 
> Confused.  What was wrong with the old code?  Was this warning
> legitimate and if so, why?  Or is this patch a workaround for a
> compiler shortcoming?

The offending line is this:

-                               memcpy(&entry.file.user_info, value,
+                               memcpy(&entry.file.info, value,
                                                file_finderinfo_len);

what it's trying to do is copy two structs which are adjacent to each
other in a single call to memcpy().  gcc legitimately complains that the
memcpy to this struct overruns the bounds of the struct.  What Gustavo
has done here is introduce a new struct that contains the two structs,
and now gcc is happy that the memcpy doesn't overrun the length of this
containing struct.

  reply	other threads:[~2021-03-31  4:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 14:52 [PATCH][next] hfsplus: Fix out-of-bounds warnings in __hfsplus_setxattr Gustavo A. R. Silva
2021-03-31  4:43 ` Andrew Morton
2021-03-31  4:53   ` Matthew Wilcox [this message]
2021-03-31 21:21     ` Gustavo A. R. Silva

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=20210331045357.GV351017@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).