David Howells 4cb6829647 afs: Fix memory leak when mounting with multiple source parameters
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)
    backtrace:
      slab_post_alloc_hook+0x42/0x79
      __kmalloc_track_caller+0x125/0x16a
      kmemdup_nul+0x24/0x3c
      vfs_parse_fs_string+0x5a/0xa1
      generic_parse_monolithic+0x9d/0xc5
      do_new_mount+0x10d/0x15a
      do_mount+0x5f/0x8e
      __do_sys_mount+0xff/0x127
      do_syscall_64+0x2d/0x3a
      entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: 13fcc6837049 ("afs: Add fs_context support")
Reported-by: syzbot+86dc6632faaca40133ab@syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-12-08 15:59:25 -08:00
..
2020-10-16 11:11:22 -07:00
2020-11-27 12:42:13 -08:00
2020-10-19 14:28:30 -07:00
2020-11-19 22:38:29 -05:00
2020-09-21 08:59:26 -07:00
2020-11-14 11:26:04 -08:00
2020-11-20 11:47:22 -08:00
\n
2020-10-15 14:56:15 -07:00
2020-10-01 11:15:31 +02:00
2020-09-10 14:03:31 -07:00
2020-10-05 10:38:33 -06:00
2020-10-19 14:28:30 -07:00
\n
2020-10-15 15:03:10 -07:00
2020-10-16 12:21:15 -07:00
2020-10-13 12:12:44 -07:00
2020-08-04 21:02:38 -04:00
2020-10-16 11:11:15 -07:00
2020-09-22 23:45:57 -04:00
2020-07-31 08:16:01 +02:00
2020-08-07 11:33:24 -07:00
2020-10-23 11:33:41 -07:00
2020-05-14 16:44:24 +02:00
2020-08-12 10:58:01 -07:00
2020-10-23 11:33:41 -07:00
2020-07-31 08:16:00 +02:00
2020-10-24 12:40:18 -07:00
2020-09-26 22:55:05 -04:00
2020-08-27 16:06:47 -04:00
2020-06-09 15:40:50 -07:00
2020-07-31 08:16:01 +02:00