aboutsummaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/overlayfs.h
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2020-05-23 16:21:55 +0300
committerMiklos Szeredi <mszeredi@redhat.com>2020-06-02 22:20:25 +0200
commit522f6e6cba6880a038e2bd88e10390b84cd3febd (patch)
tree961e5f4e11905dae3156031fe925bc4b327cb3ae /fs/overlayfs/overlayfs.h
parentovl: return required buffer size for file handles (diff)
downloadlinux-dev-522f6e6cba6880a038e2bd88e10390b84cd3febd.tar.xz
linux-dev-522f6e6cba6880a038e2bd88e10390b84cd3febd.zip
ovl: fix out of bounds access warning in ovl_check_fb_len()
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> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/overlayfs.h')
-rw-r--r--fs/overlayfs/overlayfs.h3
1 files changed, 3 insertions, 0 deletions
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);
}