fs/namespace: reject bufsize < sizeof(struct statmount) in prepare_kstatmount()
PATCH 1/1 fs/namespace: reject bufsize < sizeof(struct statmount) in prepare_kstatmount()
In prepare_kstatmount(), kstatmount.buf_size is initialized from the caller's bufsize argument without rejecting buffers smaller than sizeof(struct statmount), allowing string offset calculations relative to sizeof(struct statmount) to underflow or write past the user buffer. Reject bufsize < sizeof(struct statmount) in prepare_kstatmount().
---
fs/namespace.c +1 -1
@@ -5882,7 +5882,7 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, ks->bufsize = bufsize;if (ks->mask &STATMOUNT_STRING_REQ ) { -if (bufsize ==sizeof (ks->sm)) +if (bufsize <=sizeof (ks->sm))return -EOVERFLOW ; ks->seq.buf =kvmalloc (seq_size,GFP_KERNEL_ACCOUNT );
Quoted 9 lines · Hui Peng
In
prepare_kstatmount(), kstatmount.buf_size is initialized from the caller's bufsize argument without rejecting buffers smaller than sizeof(struct statmount), allowing string offset calculations relative to sizeof(struct statmount) to underflow or write past the user buffer. Reject bufsize < sizeof(struct statmount) inprepare_kstatmount().Fixes 68385d77c05b ("statmount: simplify string option retrieval")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Yeah, indeed it looks like we could overrun the user buffer. Feel free to add:
Honza
Quoted 14 lines
---
fs/namespace.c +1
-1@@ -5882,7 +5882,7 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, ks->bufsize = bufsize;if (ks->mask &STATMOUNT_STRING_REQ ) { -if (bufsize ==sizeof (ks->sm)) +if (bufsize <=sizeof (ks->sm))return -EOVERFLOW ; ks->seq.buf =kvmalloc (seq_size,GFP_KERNEL_ACCOUNT );
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR