Message ID | 161076031855.3386689.6419632333068855983.stgit@magnolia (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | various: random fixes | expand |
On 16 Jan 2021 at 06:55, Darrick J. Wong wrote: > From: Darrick J. Wong <djwong@kernel.org> > > Zero the memory that we pass to the kernel via ioctls so that we never > pass userspace heap/stack garbage around. This silences valgrind > complaints about uninitialized padding areas. > Looks good to me, Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com> > Signed-off-by: Darrick J. Wong <djwong@kernel.org> > --- > libhandle/handle.c | 10 ++++++---- > scrub/inodes.c | 2 +- > scrub/spacemap.c | 3 +-- > 3 files changed, 8 insertions(+), 7 deletions(-) > > > diff --git a/libhandle/handle.c b/libhandle/handle.c > index 5c1686b3..27abc6b2 100644 > --- a/libhandle/handle.c > +++ b/libhandle/handle.c > @@ -235,8 +235,10 @@ obj_to_handle( > { > char hbuf [MAXHANSIZ]; > int ret; > - uint32_t handlen; > - xfs_fsop_handlereq_t hreq; > + uint32_t handlen = 0; > + struct xfs_fsop_handlereq hreq = { }; > + > + memset(hbuf, 0, MAXHANSIZ); > > if (opcode == XFS_IOC_FD_TO_HANDLE) { > hreq.fd = obj.fd; > @@ -275,7 +277,7 @@ open_by_fshandle( > { > int fsfd; > char *path; > - xfs_fsop_handlereq_t hreq; > + struct xfs_fsop_handlereq hreq = { }; > > if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0) > return -1; > @@ -382,7 +384,7 @@ attr_list_by_handle( > { > int error, fd; > char *path; > - xfs_fsop_attrlist_handlereq_t alhreq; > + struct xfs_fsop_attrlist_handlereq alhreq = { }; > > if ((fd = handle_to_fsfd(hanp, &path)) < 0) > return -1; > diff --git a/scrub/inodes.c b/scrub/inodes.c > index bdc12df3..63865113 100644 > --- a/scrub/inodes.c > +++ b/scrub/inodes.c > @@ -111,7 +111,7 @@ scan_ag_inodes( > xfs_agnumber_t agno, > void *arg) > { > - struct xfs_handle handle; > + struct xfs_handle handle = { }; > char descr[DESCR_BUFSZ]; > struct xfs_inumbers_req *ireq; > struct xfs_bulkstat_req *breq; > diff --git a/scrub/spacemap.c b/scrub/spacemap.c > index 9653916d..a5508d56 100644 > --- a/scrub/spacemap.c > +++ b/scrub/spacemap.c > @@ -47,11 +47,10 @@ scrub_iterate_fsmap( > int i; > int error; > > - head = malloc(fsmap_sizeof(FSMAP_NR)); > + head = calloc(1, fsmap_sizeof(FSMAP_NR)); > if (!head) > return errno; > > - memset(head, 0, sizeof(*head)); > memcpy(head->fmh_keys, keys, sizeof(struct fsmap) * 2); > head->fmh_count = FSMAP_NR; >
On 1/15/21 5:28 PM, Darrick J. Wong wrote: > From: Darrick J. Wong <djwong@kernel.org> > > Zero the memory that we pass to the kernel via ioctls so that we never > pass userspace heap/stack garbage around. This silences valgrind > complaints about uninitialized padding areas. > > Signed-off-by: Darrick J. Wong <djwong@kernel.org> Looks good. Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
diff --git a/libhandle/handle.c b/libhandle/handle.c index 5c1686b3..27abc6b2 100644 --- a/libhandle/handle.c +++ b/libhandle/handle.c @@ -235,8 +235,10 @@ obj_to_handle( { char hbuf [MAXHANSIZ]; int ret; - uint32_t handlen; - xfs_fsop_handlereq_t hreq; + uint32_t handlen = 0; + struct xfs_fsop_handlereq hreq = { }; + + memset(hbuf, 0, MAXHANSIZ); if (opcode == XFS_IOC_FD_TO_HANDLE) { hreq.fd = obj.fd; @@ -275,7 +277,7 @@ open_by_fshandle( { int fsfd; char *path; - xfs_fsop_handlereq_t hreq; + struct xfs_fsop_handlereq hreq = { }; if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0) return -1; @@ -382,7 +384,7 @@ attr_list_by_handle( { int error, fd; char *path; - xfs_fsop_attrlist_handlereq_t alhreq; + struct xfs_fsop_attrlist_handlereq alhreq = { }; if ((fd = handle_to_fsfd(hanp, &path)) < 0) return -1; diff --git a/scrub/inodes.c b/scrub/inodes.c index bdc12df3..63865113 100644 --- a/scrub/inodes.c +++ b/scrub/inodes.c @@ -111,7 +111,7 @@ scan_ag_inodes( xfs_agnumber_t agno, void *arg) { - struct xfs_handle handle; + struct xfs_handle handle = { }; char descr[DESCR_BUFSZ]; struct xfs_inumbers_req *ireq; struct xfs_bulkstat_req *breq; diff --git a/scrub/spacemap.c b/scrub/spacemap.c index 9653916d..a5508d56 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -47,11 +47,10 @@ scrub_iterate_fsmap( int i; int error; - head = malloc(fsmap_sizeof(FSMAP_NR)); + head = calloc(1, fsmap_sizeof(FSMAP_NR)); if (!head) return errno; - memset(head, 0, sizeof(*head)); memcpy(head->fmh_keys, keys, sizeof(struct fsmap) * 2); head->fmh_count = FSMAP_NR;