linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ovl: Use "buf" flexible array for memcpy() destination
@ 2022-09-24  7:33 Kees Cook
  2022-09-24 16:32 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2022-09-24  7:33 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Kees Cook, linux-unionfs, syzbot+9d14351a171d0d1c7955,
	linux-kernel, linux-hardening

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>
---
 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


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

* Re: [PATCH] ovl: Use "buf" flexible array for memcpy() destination
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-24 16:32 UTC (permalink / raw)
  To: Kees Cook
  Cc: Miklos Szeredi, linux-unionfs, syzbot+9d14351a171d0d1c7955,
	linux-kernel, linux-hardening

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
> 

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

end of thread, other threads:[~2022-09-24 16:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).