All of lore.kernel.org
 help / color / mirror / Atom feed
* slab-out-of-bounds in iov_iter_revert()
@ 2020-09-11 21:59 Qian Cai
  2020-09-11 23:55 ` Al Viro
  0 siblings, 1 reply; 12+ messages in thread
From: Qian Cai @ 2020-09-11 21:59 UTC (permalink / raw)
  To: viro; +Cc: torvalds, vgoyal, miklos, linux-fsdevel, linux-kernel

Super easy to reproduce on today's mainline by just fuzzing for a few minutes
on virtiofs (if it ever matters). Any thoughts?

[  511.089112] BUG: KASAN: slab-out-of-bounds in iov_iter_revert+0xd8/0x3c0
iov_iter_revert at lib/iov_iter.c:1135
(inlined by) iov_iter_revert at lib/iov_iter.c:1080
[  511.092650] Read of size 8 at addr ffff88869e11dff8 by task trinity-c1/11868
[  511.096178] 
[  511.096897] CPU: 20 PID: 11868 Comm: trinity-c1 Not tainted 5.9.0-rc4+ #1
[  511.100257] Hardware name: Red Hat KVM, BIOS 1.14.0-1.module+el8.3.0+7638+07cf13d2 04/01/2014
[  511.103999] Call Trace:
[  511.105002]  dump_stack+0x7c/0xb0
[  511.106329]  ? iov_iter_revert+0xd8/0x3c0
[  511.107915]  print_address_description.constprop.7+0x1e/0x230
[  511.110193]  ? kmsg_dump_rewind_nolock+0x59/0x59
[  511.112038]  ? _raw_write_lock_irqsave+0xe0/0xe0
[  511.113890]  ? iov_iter_revert+0xd8/0x3c0
[  511.115469]  ? iov_iter_revert+0xd8/0x3c0
[  511.117082]  kasan_report.cold.9+0x37/0x86
[  511.118711]  ? do_readv+0x20/0x1b0
[  511.120078]  ? iov_iter_revert+0xd8/0x3c0
[  511.122614]  iov_iter_revert+0xd8/0x3c0
[  511.124673]  generic_file_read_iter+0x139/0x220
[  511.127386]  fuse_file_read_iter+0x239/0x270 [fuse]
[  511.130229]  ? fuse_direct_IO+0x600/0x600 [fuse]
[  511.133491]  ? rwsem_optimistic_spin+0x3d0/0x3d0
[  511.137177]  ? wake_up_q+0x92/0xd0
[  511.139702]  ? kasan_unpoison_shadow+0x30/0x40
[  511.142518]  do_iter_readv_writev+0x307/0x350
[  511.144850]  ? no_seek_end_llseek_size+0x20/0x20
[  511.147155]  do_iter_read+0x13f/0x2e0
[  511.148696]  vfs_readv+0xcc/0x130
[  511.150118]  ? compat_rw_copy_check_uvector+0x1e0/0x1e0
[  511.152300]  ? enqueue_hrtimer+0x60/0x100
[  511.154043]  ? hrtimer_start_range_ns+0x32f/0x4c0
[  511.157561]  ? hrtimer_run_softirq+0x100/0x100
[  511.161514]  ? _raw_spin_lock_irq+0x7b/0xd0
[  511.164570]  ? _raw_write_unlock_irqrestore+0x20/0x20
[  511.167568]  ? hrtimer_active+0x71/0xa0
[  511.169331]  ? mutex_lock+0x8e/0xe0
[  511.171694]  ? __mutex_lock_slowpath+0x10/0x10
[  511.174580]  ? perf_call_bpf_enter.isra.21+0x110/0x110
[  511.177926]  ? __fget_light+0xa3/0x100
[  511.179916]  do_readv+0xc1/0x1b0
[  511.181331]  ? vfs_readv+0x130/0x130
[  511.182867]  ? ktime_get_coarse_real_ts64+0x4a/0x70
[  511.185455]  do_syscall_64+0x33/0x40
[  511.188008]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[  511.191314] RIP: 0033:0x7f11e9b4578d
[  511.193639] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d cb 56 2c 00 f7 d8 64 89 08
[  511.202148] RSP: 002b:00007fff9b5eec58 EFLAGS: 00000246 ORIG_RAX: 0000000000000013
[  511.205620] RAX: ffffffffffffffda RBX: 0000000000000013 RCX: 00007f11e9b4578d
[  511.210533] RDX: 0000000000000091 RSI: 0000000002c49450 RDI: 00000000000000e1
[  511.214992] RBP: 0000000000000013 R08: 000000008d8d8d8d R09: 00000000000002d2
[  511.218631] R10: 00000020845754a0 R11: 0000000000000246 R12: 0000000000000002
[  511.221595] R13: 00007f11ea227058 R14: 00007f11ea2356c0 R15: 00007f11ea227000
[  511.225949] 
[  511.227008] Allocated by task 11748:
[  511.229204]  kasan_save_stack+0x19/0x40
[  511.231404]  __kasan_kmalloc.constprop.8+0xc1/0xd0
[  511.234647]  perf_event_mmap+0x28f/0x5f0
[  511.237170]  mmap_region+0x1cc/0xa50
[  511.239192]  do_mmap+0x3e5/0x6a0
[  511.241337]  vm_mmap_pgoff+0x15f/0x1b0
[  511.243586]  ksys_mmap_pgoff+0x2d3/0x320
[  511.245903]  do_syscall_64+0x33/0x40
[  511.247914]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[  511.250139] 
[  511.250797] Freed by task 11748:
[  511.252160]  kasan_save_stack+0x19/0x40
[  511.253775]  kasan_set_track+0x1c/0x30
[  511.255348]  kasan_set_free_info+0x1b/0x30
[  511.257072]  __kasan_slab_free+0x108/0x150
[  511.258785]  kfree+0x95/0x380
[  511.260050]  perf_event_mmap+0x4aa/0x5f0
[  511.261694]  mmap_region+0x1cc/0xa50
[  511.263198]  do_mmap+0x3e5/0x6a0
[  511.264564]  vm_mmap_pgoff+0x15f/0x1b0
[  511.266133]  ksys_mmap_pgoff+0x2d3/0x320
[  511.267773]  do_syscall_64+0x33/0x40
[  511.269276]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[  511.272756] 
[  511.273583] The buggy address belongs to the object at ffff88869e11c000
[  511.273583]  which belongs to the cache kmalloc-4k of size 4096
[  511.281456] The buggy address is located 4088 bytes to the right of
[  511.281456]  4096-byte region [ffff88869e11c000, ffff88869e11d000)
[  511.288473] The buggy address belongs to the page:
[  511.291093] page:0000000073d20fbc refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x69e118
[  511.296681] head:0000000073d20fbc order:3 compound_mapcount:0 compound_pincount:0
[  511.301118] flags: 0x17ffffc0010200(slab|head)
[  511.303426] raw: 0017ffffc0010200 0000000000000000 0000000300000001 ffff888107c4ef80
[  511.307482] raw: 0000000000000000 0000000000040004 00000001ffffffff 0000000000000000
[  511.310957] page dumped because: kasan: bad access detected
[  511.313233] 
[  511.313867] Memory state around the buggy address:
[  511.315849]  ffff88869e11de80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  511.318933]  ffff88869e11df00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  511.322715] >ffff88869e11df80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  511.325993]                                                                 ^
[  511.330020]  ffff88869e11e000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[  511.334333]  ffff88869e11e080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: slab-out-of-bounds in iov_iter_revert()
@ 2020-09-17 13:46 kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2020-09-17 13:46 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 10041 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200917020440.GQ3421308@ZenIV.linux.org.uk>
References: <20200917020440.GQ3421308@ZenIV.linux.org.uk>
TO: Al Viro <viro@zeniv.linux.org.uk>
TO: Qian Cai <cai@redhat.com>
CC: torvalds(a)linux-foundation.org
CC: vgoyal(a)redhat.com
CC: miklos(a)szeredi.hu
CC: linux-fsdevel(a)vger.kernel.org
CC: linux-kernel(a)vger.kernel.org

Hi Al,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on fuse/for-next]
[also build test WARNING on linux/master linus/master v5.9-rc5 next-20200917]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Al-Viro/Re-slab-out-of-bounds-in-iov_iter_revert/20200917-100520
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git for-next
:::::: branch date: 12 hours ago
:::::: commit date: 12 hours ago
config: x86_64-randconfig-m001-20200917 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
fs/fuse/file.c:3205 fuse_direct_IO() error: uninitialized symbol 'shortened'.

# https://github.com/0day-ci/linux/commit/cf78ce1d71bfd0c3c06adfd5bba1664c61e36bbd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Al-Viro/Re-slab-out-of-bounds-in-iov_iter_revert/20200917-100520
git checkout cf78ce1d71bfd0c3c06adfd5bba1664c61e36bbd
vim +/shortened +3205 fs/fuse/file.c

e5c5f05dca0cf90 Maxim Patlasov        2013-05-30  3110  
4273b793ec68753 Anand Avati           2012-02-17  3111  static ssize_t
c8b8e32d700fe94 Christoph Hellwig     2016-04-07  3112  fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
4273b793ec68753 Anand Avati           2012-02-17  3113  {
9d5722b7777e64d Christoph Hellwig     2015-02-02  3114  	DECLARE_COMPLETION_ONSTACK(wait);
4273b793ec68753 Anand Avati           2012-02-17  3115  	ssize_t ret = 0;
60b9df7a54804a9 Miklos Szeredi        2013-05-01  3116  	struct file *file = iocb->ki_filp;
60b9df7a54804a9 Miklos Szeredi        2013-05-01  3117  	struct fuse_file *ff = file->private_data;
e5c5f05dca0cf90 Maxim Patlasov        2013-05-30  3118  	bool async_dio = ff->fc->async_dio;
4273b793ec68753 Anand Avati           2012-02-17  3119  	loff_t pos = 0;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3120  	struct inode *inode;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3121  	loff_t i_size;
cf78ce1d71bfd0c Al Viro               2020-09-17  3122  	size_t count = iov_iter_count(iter), shortened;
c8b8e32d700fe94 Christoph Hellwig     2016-04-07  3123  	loff_t offset = iocb->ki_pos;
36cf66ed9f871fc Maxim Patlasov        2012-12-14  3124  	struct fuse_io_priv *io;
4273b793ec68753 Anand Avati           2012-02-17  3125  
4273b793ec68753 Anand Avati           2012-02-17  3126  	pos = offset;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3127  	inode = file->f_mapping->host;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3128  	i_size = i_size_read(inode);
4273b793ec68753 Anand Avati           2012-02-17  3129  
6f67376318abea5 Omar Sandoval         2015-03-16  3130  	if ((iov_iter_rw(iter) == READ) && (offset > i_size))
9fe55eea7e4b444 Steven Whitehouse     2014-01-24  3131  		return 0;
9fe55eea7e4b444 Steven Whitehouse     2014-01-24  3132  
439ee5f0c5080d4 Maxim Patlasov        2012-12-14  3133  	/* optimization for short read */
6f67376318abea5 Omar Sandoval         2015-03-16  3134  	if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) {
439ee5f0c5080d4 Maxim Patlasov        2012-12-14  3135  		if (offset >= i_size)
439ee5f0c5080d4 Maxim Patlasov        2012-12-14  3136  			return 0;
5da784cce4308ae Constantine Shulyupin 2018-09-06  3137  		iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset));
cf78ce1d71bfd0c Al Viro               2020-09-17  3138  		shortened = count - iov_iter_count(iter);
cf78ce1d71bfd0c Al Viro               2020-09-17  3139  		count -= shortened;
439ee5f0c5080d4 Maxim Patlasov        2012-12-14  3140  	}
439ee5f0c5080d4 Maxim Patlasov        2012-12-14  3141  
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3142  	io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
36cf66ed9f871fc Maxim Patlasov        2012-12-14  3143  	if (!io)
36cf66ed9f871fc Maxim Patlasov        2012-12-14  3144  		return -ENOMEM;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3145  	spin_lock_init(&io->lock);
744742d692e37ad Seth Forshee          2016-03-11  3146  	kref_init(&io->refcnt);
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3147  	io->reqs = 1;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3148  	io->bytes = -1;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3149  	io->size = 0;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3150  	io->offset = offset;
6f67376318abea5 Omar Sandoval         2015-03-16  3151  	io->write = (iov_iter_rw(iter) == WRITE);
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3152  	io->err = 0;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3153  	/*
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3154  	 * By default, we want to optimize all I/Os with async request
60b9df7a54804a9 Miklos Szeredi        2013-05-01  3155  	 * submission to the client filesystem if supported.
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3156  	 */
e5c5f05dca0cf90 Maxim Patlasov        2013-05-30  3157  	io->async = async_dio;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3158  	io->iocb = iocb;
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3159  	io->blocking = is_sync_kiocb(iocb);
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3160  
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3161  	/*
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3162  	 * We cannot asynchronously extend the size of a file.
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3163  	 * In such case the aio will behave exactly like sync io.
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3164  	 */
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3165  	if ((offset + count > i_size) && iov_iter_rw(iter) == WRITE)
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3166  		io->blocking = true;
4273b793ec68753 Anand Avati           2012-02-17  3167  
7879c4e58b7c884 Ashish Sangwan        2016-04-07  3168  	if (io->async && io->blocking) {
744742d692e37ad Seth Forshee          2016-03-11  3169  		/*
744742d692e37ad Seth Forshee          2016-03-11  3170  		 * Additional reference to keep io around after
744742d692e37ad Seth Forshee          2016-03-11  3171  		 * calling fuse_aio_complete()
744742d692e37ad Seth Forshee          2016-03-11  3172  		 */
744742d692e37ad Seth Forshee          2016-03-11  3173  		kref_get(&io->refcnt);
9d5722b7777e64d Christoph Hellwig     2015-02-02  3174  		io->done = &wait;
744742d692e37ad Seth Forshee          2016-03-11  3175  	}
9d5722b7777e64d Christoph Hellwig     2015-02-02  3176  
6f67376318abea5 Omar Sandoval         2015-03-16  3177  	if (iov_iter_rw(iter) == WRITE) {
812408fb51ef580 Al Viro               2015-03-30  3178  		ret = fuse_direct_io(io, iter, &pos, FUSE_DIO_WRITE);
812408fb51ef580 Al Viro               2015-03-30  3179  		fuse_invalidate_attr(inode);
812408fb51ef580 Al Viro               2015-03-30  3180  	} else {
d22a943f44c79c9 Al Viro               2014-03-16  3181  		ret = __fuse_direct_read(io, iter, &pos);
812408fb51ef580 Al Viro               2015-03-30  3182  	}
36cf66ed9f871fc Maxim Patlasov        2012-12-14  3183  
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3184  	if (io->async) {
ebacb8127359955 Lukas Czerner         2018-11-09  3185  		bool blocking = io->blocking;
ebacb8127359955 Lukas Czerner         2018-11-09  3186  
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3187  		fuse_aio_complete(io, ret < 0 ? ret : 0, -1);
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3188  
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3189  		/* we have a non-extending, async request, so return */
ebacb8127359955 Lukas Czerner         2018-11-09  3190  		if (!blocking)
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3191  			return -EIOCBQUEUED;
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3192  
9d5722b7777e64d Christoph Hellwig     2015-02-02  3193  		wait_for_completion(&wait);
9d5722b7777e64d Christoph Hellwig     2015-02-02  3194  		ret = fuse_get_res_by_io(io);
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3195  	}
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3196  
744742d692e37ad Seth Forshee          2016-03-11  3197  	kref_put(&io->refcnt, fuse_io_release);
9d5722b7777e64d Christoph Hellwig     2015-02-02  3198  
6f67376318abea5 Omar Sandoval         2015-03-16  3199  	if (iov_iter_rw(iter) == WRITE) {
efb9fa9e911b23c Maxim Patlasov        2012-12-18  3200  		if (ret > 0)
bcba24ccdc82f74 Maxim Patlasov        2012-12-14  3201  			fuse_write_update_size(inode, pos);
efb9fa9e911b23c Maxim Patlasov        2012-12-18  3202  		else if (ret < 0 && offset + count > i_size)
efb9fa9e911b23c Maxim Patlasov        2012-12-18  3203  			fuse_do_truncate(file);
efb9fa9e911b23c Maxim Patlasov        2012-12-18  3204  	}
cf78ce1d71bfd0c Al Viro               2020-09-17 @3205  	if (shortened)
cf78ce1d71bfd0c Al Viro               2020-09-17  3206  		iov_iter_reexpand(iter, shortened);
4273b793ec68753 Anand Avati           2012-02-17  3207  
4273b793ec68753 Anand Avati           2012-02-17  3208  	return ret;
4273b793ec68753 Anand Avati           2012-02-17  3209  }
4273b793ec68753 Anand Avati           2012-02-17  3210  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30052 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-09-17 20:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-11 21:59 slab-out-of-bounds in iov_iter_revert() Qian Cai
2020-09-11 23:55 ` Al Viro
2020-09-16 21:09   ` Qian Cai
2020-09-17  2:04     ` Al Viro
2020-09-17  2:14       ` Al Viro
2020-09-17 14:10         ` Qian Cai
2020-09-17 16:44           ` Al Viro
2020-09-17 17:42             ` Qian Cai
2020-09-17 18:45               ` Al Viro
2020-09-17 20:16                 ` Qian Cai
2020-09-17 18:45             ` Qian Cai
  -- strict thread matches above, loose matches on Subject: below --
2020-09-17 13:46 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.