All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	linux-unionfs@vger.kernel.org,
	syzbot+9d14351a171d0d1c7955@syzkaller.appspotmail.com,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] ovl: Use "buf" flexible array for memcpy() destination
Date: Sat, 24 Sep 2022 11:32:54 -0500	[thread overview]
Message-ID: <Yy8xNjsZ1N/wbV8s@work> (raw)
In-Reply-To: <20220924073315.3593031-1-keescook@chromium.org>

On Sat, Sep 24, 2022 at 12:33:15AM -0700, Kees Cook wrote:
> The "buf" flexible array needs to be the memcpy() destination to avoid
> false positive run-time warning from the recent FORTIFY_SOURCE
> hardening:
> 
>   memcpy: detected field-spanning write (size 93) of single field "&fh->fb" at fs/overlayfs/export.c:799 (size 21)
> 
> Cc: Miklos Szeredi <miklos@szeredi.hu>
> Cc: linux-unionfs@vger.kernel.org
> Reported-by: syzbot+9d14351a171d0d1c7955@syzkaller.appspotmail.com
> Link: https://lore.kernel.org/all/000000000000763a6c05e95a5985@google.com/
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  fs/overlayfs/export.c    | 2 +-
>  fs/overlayfs/overlayfs.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
> index e065a5b9a442..ac9c3ad04016 100644
> --- a/fs/overlayfs/export.c
> +++ b/fs/overlayfs/export.c
> @@ -796,7 +796,7 @@ static struct ovl_fh *ovl_fid_to_fh(struct fid *fid, int buflen, int fh_type)
>  		return ERR_PTR(-ENOMEM);
>  
>  	/* Copy unaligned inner fh into aligned buffer */
> -	memcpy(&fh->fb, fid, buflen - OVL_FH_WIRE_OFFSET);
> +	memcpy(fh->buf, fid, buflen - OVL_FH_WIRE_OFFSET);
>  	return fh;
>  }
>  
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 87759165d32b..a0e450313ea4 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -108,7 +108,7 @@ struct ovl_fh {
>  	u8 padding[3];	/* make sure fb.fid is 32bit aligned */
>  	union {
>  		struct ovl_fb fb;
> -		u8 buf[0];
> +		DECLARE_FLEX_ARRAY(u8, buf);
>  	};
>  } __packed;
>  
> -- 
> 2.34.1
> 

      reply	other threads:[~2022-09-24 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24  7:33 [PATCH] ovl: Use "buf" flexible array for memcpy() destination Kees Cook
2022-09-24 16:32 ` Gustavo A. R. Silva [this message]

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=Yy8xNjsZ1N/wbV8s@work \
    --to=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=syzbot+9d14351a171d0d1c7955@syzkaller.appspotmail.com \
    /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 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.