Skip to content

Commit ed40866

Browse files
iii-iAlexander Gordeev
authored andcommitted
statfs: enforce statfs[64] structure initialization
s390's struct statfs and struct statfs64 contain padding, which field-by-field copying does not set. Initialize the respective structs with zeros before filling them and copying them to userspace, like it's already done for the compat versions of these structs. Found by KMSAN. [agordeev@linux.ibm.com: fixed typo in patch description] Acked-by: Heiko Carstens <hca@linux.ibm.com> Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Link: https://lore.kernel.org/r/20230504144021.808932-2-iii@linux.ibm.com Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent 2862a2f commit ed40866

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

fs/statfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static int do_statfs_native(struct kstatfs *st, struct statfs __user *p)
130130
if (sizeof(buf) == sizeof(*st))
131131
memcpy(&buf, st, sizeof(*st));
132132
else {
133+
memset(&buf, 0, sizeof(buf));
133134
if (sizeof buf.f_blocks == 4) {
134135
if ((st->f_blocks | st->f_bfree | st->f_bavail |
135136
st->f_bsize | st->f_frsize) &
@@ -158,7 +159,6 @@ static int do_statfs_native(struct kstatfs *st, struct statfs __user *p)
158159
buf.f_namelen = st->f_namelen;
159160
buf.f_frsize = st->f_frsize;
160161
buf.f_flags = st->f_flags;
161-
memset(buf.f_spare, 0, sizeof(buf.f_spare));
162162
}
163163
if (copy_to_user(p, &buf, sizeof(buf)))
164164
return -EFAULT;
@@ -171,6 +171,7 @@ static int do_statfs64(struct kstatfs *st, struct statfs64 __user *p)
171171
if (sizeof(buf) == sizeof(*st))
172172
memcpy(&buf, st, sizeof(*st));
173173
else {
174+
memset(&buf, 0, sizeof(buf));
174175
buf.f_type = st->f_type;
175176
buf.f_bsize = st->f_bsize;
176177
buf.f_blocks = st->f_blocks;
@@ -182,7 +183,6 @@ static int do_statfs64(struct kstatfs *st, struct statfs64 __user *p)
182183
buf.f_namelen = st->f_namelen;
183184
buf.f_frsize = st->f_frsize;
184185
buf.f_flags = st->f_flags;
185-
memset(buf.f_spare, 0, sizeof(buf.f_spare));
186186
}
187187
if (copy_to_user(p, &buf, sizeof(buf)))
188188
return -EFAULT;

0 commit comments

Comments
 (0)