There's a memory leak in afs_parse_source() whereby multiple source= parameters overwrite fc->source in the fs_context struct without freeing the previously recorded source. Fix this by only permitting a single source parameter and rejecting with an error all subsequent ones. This was caught by syzbot with the kernel memory leak detector, showing something like the following trace: unreferenced object 0xffff888114375440 (size 32): comm "repro", pid 5168, jiffies 4294923723 (age 569.948s) hex dump (first 32 bytes): 25 5e 5d 24 5b 2b 25 5d 28 24 7b 3a 0f 6b 5b 29 %^]$[+%](${:.k[) 2d 3a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -:.............. backtrace: [<0000000072e41e46>] slab_post_alloc_hook+0x42/0x79 [<00000000d8b306e6>] __kmalloc_track_caller+0x125/0x16a [<0000000028ae1813>] kmemdup_nul+0x24/0x3c [<0000000072927516>] vfs_parse_fs_string+0x5a/0xa1 [<0000000045b4b196>] generic_parse_monolithic+0x9d/0xc5 [<0000000084462c80>] do_new_mount+0x10d/0x15a [<000000008aef98c5>] do_mount+0x5f/0x8e [<000000002998d632>] __do_sys_mount+0xff/0x127 [<00000000faf86d94>] do_syscall_64+0x2d/0x3a [<000000004495c173>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 13fcc6837049 ("afs: Add fs_context support") Reported-by: syzbot+86dc6632faaca40133ab@xxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: David Howells <dhowells@xxxxxxxxxx> cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> --- fs/afs/super.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/afs/super.c b/fs/afs/super.c index 6c5900df6aa5..e38bb1e7a4d2 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c @@ -230,6 +230,9 @@ static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param) _enter(",%s", name); + if (fc->source) + return invalf(fc, "kAFS: Multiple sources not supported"); + if (!name) { printk(KERN_ERR "kAFS: no volume name specified\n"); return -EINVAL;