linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ovl: fix out of bounds access warning in ovl_check_fb_len()
@ 2020-05-23 13:21 Amir Goldstein
  2020-06-02  8:07 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-05-23 13:21 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: Dan Carpenter, syzkaller-bugs, linux-unionfs

syzbot reported out of bounds memory access from open_by_handle_at()
with a crafted file handle that looks like this:

  { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }

handle_bytes gets rounded down to 0 and we end up calling:
  ovl_check_fh_len(fh, 0) => ovl_check_fb_len(fh + 3, -3)

But fh buffer is only 2 bytes long, so accessing struct ovl_fb at
fh + 3 is illegal.

Fixes: cbe7fba8edfc ("ovl: make sure that real fid is 32bit aligned in memory")
Reported-and-tested-by: syzbot+61958888b1c60361a791@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org> # v5.5
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Miklos,

Another fallout from aligned file handle.
This one seems like a warning that cannot lead to actual harm.
As far as I can tell, with:

  { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }

kmalloc in handle_to_path() allocates 10 bytes, which means 16 bytes
slab object, so all fields accessed by ovl_check_fh_len() should be
within the slab object boundaries. And in any case, their value
won't change the outcome of EINVAL.

I have added this use case to the xfstest for checking the first bug,
but it doesn't trigger any warning on my kernel (without KASAN) and
returns EINVAL as expected.

Thanks,
Amir.

 fs/overlayfs/overlayfs.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 76747f5b0517..ffbb57b2d7f6 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -355,6 +355,9 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
 
 static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
 {
+	if (fh_len < sizeof(struct ovl_fh))
+		return -EINVAL;
+
 	return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
 }
 
-- 
2.17.1


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

* Re: [PATCH] ovl: fix out of bounds access warning in ovl_check_fb_len()
  2020-05-23 13:21 [PATCH] ovl: fix out of bounds access warning in ovl_check_fb_len() Amir Goldstein
@ 2020-06-02  8:07 ` Amir Goldstein
  2020-06-02  8:22   ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-06-02  8:07 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: Dan Carpenter, syzkaller-bugs, overlayfs

On Sat, May 23, 2020 at 4:22 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> syzbot reported out of bounds memory access from open_by_handle_at()
> with a crafted file handle that looks like this:
>
>   { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }
>
> handle_bytes gets rounded down to 0 and we end up calling:
>   ovl_check_fh_len(fh, 0) => ovl_check_fb_len(fh + 3, -3)
>
> But fh buffer is only 2 bytes long, so accessing struct ovl_fb at
> fh + 3 is illegal.
>
> Fixes: cbe7fba8edfc ("ovl: make sure that real fid is 32bit aligned in memory")
> Reported-and-tested-by: syzbot+61958888b1c60361a791@syzkaller.appspotmail.com
> Cc: <stable@vger.kernel.org> # v5.5
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>
> Miklos,
>

Ping.

> Another fallout from aligned file handle.
> This one seems like a warning that cannot lead to actual harm.
> As far as I can tell, with:
>
>   { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }
>
> kmalloc in handle_to_path() allocates 10 bytes, which means 16 bytes
> slab object, so all fields accessed by ovl_check_fh_len() should be
> within the slab object boundaries. And in any case, their value
> won't change the outcome of EINVAL.
>
> I have added this use case to the xfstest for checking the first bug,
> but it doesn't trigger any warning on my kernel (without KASAN) and
> returns EINVAL as expected.
>
> Thanks,
> Amir.
>
>  fs/overlayfs/overlayfs.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 76747f5b0517..ffbb57b2d7f6 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -355,6 +355,9 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
>
>  static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
>  {
> +       if (fh_len < sizeof(struct ovl_fh))
> +               return -EINVAL;
> +
>         return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
>  }
>
> --
> 2.17.1
>

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

* Re: [PATCH] ovl: fix out of bounds access warning in ovl_check_fb_len()
  2020-06-02  8:07 ` Amir Goldstein
@ 2020-06-02  8:22   ` Miklos Szeredi
  0 siblings, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2020-06-02  8:22 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Dan Carpenter, syzkaller-bugs, overlayfs

On Tue, Jun 2, 2020 at 10:07 AM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Sat, May 23, 2020 at 4:22 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > syzbot reported out of bounds memory access from open_by_handle_at()
> > with a crafted file handle that looks like this:
> >
> >   { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }
> >
> > handle_bytes gets rounded down to 0 and we end up calling:
> >   ovl_check_fh_len(fh, 0) => ovl_check_fb_len(fh + 3, -3)
> >
> > But fh buffer is only 2 bytes long, so accessing struct ovl_fb at
> > fh + 3 is illegal.
> >
> > Fixes: cbe7fba8edfc ("ovl: make sure that real fid is 32bit aligned in memory")
> > Reported-and-tested-by: syzbot+61958888b1c60361a791@syzkaller.appspotmail.com
> > Cc: <stable@vger.kernel.org> # v5.5
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> >
> > Miklos,
> >
>
> Ping.
>
> > Another fallout from aligned file handle.
> > This one seems like a warning that cannot lead to actual harm.
> > As far as I can tell, with:
> >
> >   { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }
> >
> > kmalloc in handle_to_path() allocates 10 bytes, which means 16 bytes
> > slab object, so all fields accessed by ovl_check_fh_len() should be
> > within the slab object boundaries. And in any case, their value
> > won't change the outcome of EINVAL.
> >
> > I have added this use case to the xfstest for checking the first bug,
> > but it doesn't trigger any warning on my kernel (without KASAN) and
> > returns EINVAL as expected.

Applied, thanks.

Miklos

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

end of thread, other threads:[~2020-06-02  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 13:21 [PATCH] ovl: fix out of bounds access warning in ovl_check_fb_len() Amir Goldstein
2020-06-02  8:07 ` Amir Goldstein
2020-06-02  8:22   ` Miklos Szeredi

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