Message ID | 20211107124845.1174791-3-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | linux-user: Fix getdents alignment issues (#704) | expand |
On 11/7/21 13:48, Richard Henderson wrote: > We currently use a flexible array member for target_dirent, > but use incorrectly fixed length arrays for target_dirent64, > linux_dirent and linux_dirent64. > > This requires that we adjust the definition of the VFAT READDIR > ioctls which hard-code the 256 namelen size into the ioctl constant. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > linux-user/syscall_defs.h | 6 +++--- > linux-user/syscall.c | 6 ++++-- > 2 files changed, 7 insertions(+), 5 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> On Nov 7, 2021, at 5:48 AM, Richard Henderson <richard.henderson@linaro.org> wrote: > > We currently use a flexible array member for target_dirent, > but use incorrectly fixed length arrays for target_dirent64, > linux_dirent and linux_dirent64. > > This requires that we adjust the definition of the VFAT READDIR > ioctls which hard-code the 256 namelen size into the ioctl constant. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > linux-user/syscall_defs.h | 6 +++--- > linux-user/syscall.c | 6 ++++-- > 2 files changed, 7 insertions(+), 5 deletions(-) Reviewed by: Warner Losh <imp@bsdimp.com> > diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h > index a5ce487dcc..98b09ee6d6 100644 > --- a/linux-user/syscall_defs.h > +++ b/linux-user/syscall_defs.h > @@ -441,7 +441,7 @@ struct target_dirent64 { > int64_t d_off; > unsigned short d_reclen; > unsigned char d_type; > - char d_name[256]; > + char d_name[]; > }; > > > @@ -2714,7 +2714,7 @@ struct linux_dirent { > long d_ino; > unsigned long d_off; > unsigned short d_reclen; > - char d_name[256]; /* We must not include limits.h! */ > + char d_name[]; > }; > > struct linux_dirent64 { > @@ -2722,7 +2722,7 @@ struct linux_dirent64 { > int64_t d_off; > unsigned short d_reclen; > unsigned char d_type; > - char d_name[256]; > + char d_name[]; > }; > > struct target_mq_attr { > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index a2f605dec4..499415ad81 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -197,8 +197,10 @@ > //#define DEBUG_ERESTARTSYS > > //#include <linux/msdos_fs.h> > -#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) > -#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) > +#define VFAT_IOCTL_READDIR_BOTH \ > + _IOC(_IOC_READ, 'r', 1, (sizeof(struct linux_dirent) + 256) * 2) > +#define VFAT_IOCTL_READDIR_SHORT \ > + _IOC(_IOC_READ, 'r', 2, (sizeof(struct linux_dirent) + 256) * 2) > > #undef _syscall0 > #undef _syscall1 > -- > 2.25.1 > >
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index a5ce487dcc..98b09ee6d6 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -441,7 +441,7 @@ struct target_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; @@ -2714,7 +2714,7 @@ struct linux_dirent { long d_ino; unsigned long d_off; unsigned short d_reclen; - char d_name[256]; /* We must not include limits.h! */ + char d_name[]; }; struct linux_dirent64 { @@ -2722,7 +2722,7 @@ struct linux_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; struct target_mq_attr { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2f605dec4..499415ad81 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -197,8 +197,10 @@ //#define DEBUG_ERESTARTSYS //#include <linux/msdos_fs.h> -#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) -#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) +#define VFAT_IOCTL_READDIR_BOTH \ + _IOC(_IOC_READ, 'r', 1, (sizeof(struct linux_dirent) + 256) * 2) +#define VFAT_IOCTL_READDIR_SHORT \ + _IOC(_IOC_READ, 'r', 2, (sizeof(struct linux_dirent) + 256) * 2) #undef _syscall0 #undef _syscall1
We currently use a flexible array member for target_dirent, but use incorrectly fixed length arrays for target_dirent64, linux_dirent and linux_dirent64. This requires that we adjust the definition of the VFAT READDIR ioctls which hard-code the 256 namelen size into the ioctl constant. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- linux-user/syscall_defs.h | 6 +++--- linux-user/syscall.c | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-)