Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3272855imm; Tue, 29 May 2018 04:27:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZonGOwTFteP/oU0l55tbSAjuweeNh1j7rrMZab6o/GjRMieE/sSDer/ZQOly68O4fOWH7Er X-Received: by 2002:a17:902:4483:: with SMTP id l3-v6mr17394282pld.282.1527593263342; Tue, 29 May 2018 04:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527593263; cv=none; d=google.com; s=arc-20160816; b=C3CFKEt+HctKoElb4u6c3iV580owOcVbt/NMx5/J7M0ZXwwdvbwEGo2ZHxXBfBI7GJ B2DyL//7B9q1EuxEJLm18vhTlLj0BX7HjXSOOAVEGtla4e8jgY2PuDnnSwOnINCDjjac 2hZvw2DfooDB/cdB+xfG+b4yLRuTqrhq34hkNjm7c0RhreOE6hIWdLkes5q8YuSz99af O4z8yfLmGDgx+NZWYwNlog7sAlh8+uI0NGOpGTOQG0SqKh/JKdchbpG8LSmW/a8rArWa nXXXpc1ULn7BTLm1gpYKP4XXfAH+L+y64NkeRu8FhwL2Cimxh06tu/ZOSlE5Dk+JiP/z yF8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=DHbAvsmPOeRp5GAt8he2xUCuTZ4/r1mxT6hK5bcs1iw=; b=lO0wM9isrJmLb83AnbuEg8XyA+PSSej0jy2AXKxFAJ9DeLzifRR2uX4r4tt7DktWSN +scg4BPGyONFW2ofmEhmdjbfXsmCp/iFPpLBWXvLSDg8zCFZrXQ5Q8UwrXN4aFeN9Xw6 xX0HS2EffMhGFG971roWxL1KyYffgEeOKETM7W0OofbLJau7g1utumTqFlwhBGaMwcBZ /6enK6xKy5hOjtkIBHpT7ApojczaxMhXvi11RMvHb5ptMEHtVPWloEyr1bIA+s918xiu tvMRWlzJ08dz/ZhQPzvzzrUazspyv9+TPdYnCjL1BwPfRVihoJN4svRU20QMNbQNBvZw JB4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W6oBJvcj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k127-v6si25297561pgk.256.2018.05.29.04.27.28; Tue, 29 May 2018 04:27:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W6oBJvcj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933322AbeE2L1C (ORCPT + 99 others); Tue, 29 May 2018 07:27:02 -0400 Received: from mail-vk0-f66.google.com ([209.85.213.66]:45185 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932949AbeE2L07 (ORCPT ); Tue, 29 May 2018 07:26:59 -0400 Received: by mail-vk0-f66.google.com with SMTP id n134-v6so8619007vke.12; Tue, 29 May 2018 04:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=DHbAvsmPOeRp5GAt8he2xUCuTZ4/r1mxT6hK5bcs1iw=; b=W6oBJvcjNsFoL8IrygJylx11RmlZ5AN7ChAEfFnz3oyIx4pkVIafIn+ygkyIAASYX8 CozK88rtZrLSexF5FucYfsnwO8XYpb1bkld6bPJiOswCyBr33c0YtPuNmeloZLu5yMU4 mIFU+vXh4Qm9Tccnt0JKeAp4u7KEgnmHobCAvveuVR24liXhHNBpOzqAjbaNt/KhpouM GDdKpzDfcYQ5YjPIvCn0m07uO/CFW+NSYX7tge6aLOe9eTPsbZzJ6gYDHJcZ1Cx3NPr0 XhzenQ+upEP3shxiN7TyTcnrblyCvfoH4YGj7QX4w8oDGQ+qlkfNP9H42eZ5ybXgjrLS pJHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=DHbAvsmPOeRp5GAt8he2xUCuTZ4/r1mxT6hK5bcs1iw=; b=Hj+XIODIXv5D6Ij/1qdZjF7g4tdJX5dnyim6n/ihQZmr+PCIyz3aEaDZTcTnx3OdQo 2hvhbspGYUki1KMFmZnqXQi4RfLV8bx4ImRpHdYQ21tnvq/WXT0CZMHrinDTfPS6d7Ej 5gwUy4J8dnZUwDyOu0qvNsaywXzuSb+hdasPRgxB3N+Ww/W12x2VLv2K+NmUWEuwrmMu thhgO0uI5cmhjdtV1L286UuHvk621TYmHBVrxRhLOncD0Wqix5qhz2ykCd2iA+wtqSWj 4oBEbs6TC2E78fnI0OyQHE3UEeOq19PSch1J7DHsmb9876UHGVd00lq692NpGT7ucXPd tv/Q== X-Gm-Message-State: ALKqPwfxtcp6xw3fYS/C09hm2NBuE4lAkXWD8AD/2UML/M2n763jEKJt WGpzy+XUgQzH8bYHCldDiccLJqOL1mckKz71JN0= X-Received: by 2002:a1f:b30b:: with SMTP id c11-v6mr9786504vkf.112.1527593218313; Tue, 29 May 2018 04:26:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:6982:0:0:0:0:0 with HTTP; Tue, 29 May 2018 04:26:57 -0700 (PDT) In-Reply-To: <20180528173740.26491-1-lhenriques@suse.com> References: <20180528173740.26491-1-lhenriques@suse.com> From: "Yan, Zheng" Date: Tue, 29 May 2018 19:26:57 +0800 Message-ID: Subject: Re: [PATCH] ceph: fix use-after-free in ceph_statfs To: Luis Henriques Cc: "Yan, Zheng" , Sage Weil , Ilya Dryomov , ceph-devel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 1:37 AM, Luis Henriques wrote: > KASAN found an UAF in ceph_statfs. This was a one-off bug but looking at > the code it looks like the monmap access needs to be protected as it can > be modified while we're accessing it. Fix this by protecting the access > with the monc->mutex. > > [ 234.282067] BUG: KASAN: use-after-free in ceph_statfs+0x21d/0x2c0 > [ 234.284109] Read of size 8 at addr ffff88006844f2e0 by task trinity-c5/304 > > [ 234.287646] CPU: 0 PID: 304 Comm: trinity-c5 Not tainted 4.17.0-rc6+ #172 > [ 234.289831] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 > [ 234.292220] Call Trace: > [ 234.292576] dump_stack+0xa5/0x11b > [ 234.293091] ? show_regs_print_info+0x5/0x5 > [ 234.293663] ? kmsg_dump_rewind+0x118/0x118 > [ 234.294258] ? ceph_statfs+0x21d/0x2c0 > [ 234.294762] print_address_description+0x73/0x2b0 > [ 234.295387] ? ceph_statfs+0x21d/0x2c0 > [ 234.295923] kasan_report+0x243/0x360 > [ 234.296445] ceph_statfs+0x21d/0x2c0 > [ 234.296944] ? ceph_umount_begin+0x80/0x80 > [ 234.297514] ? kmem_cache_alloc+0xdf/0x1a0 > [ 234.298092] statfs_by_dentry+0x79/0xb0 > [ 234.298801] vfs_statfs+0x28/0x110 > [ 234.299398] user_statfs+0x8c/0xe0 > [ 234.299915] ? vfs_statfs+0x110/0x110 > [ 234.300469] ? __fdget_raw+0x10/0x10 > [ 234.301163] __se_sys_statfs+0x5d/0xa0 > [ 234.301872] ? user_statfs+0xe0/0xe0 > [ 234.302566] ? mutex_unlock+0x1d/0x40 > [ 234.303186] ? __x64_sys_statfs+0x20/0x30 > [ 234.303880] do_syscall_64+0xee/0x290 > [ 234.304488] ? syscall_return_slowpath+0x1c0/0x1c0 > [ 234.305316] ? page_fault+0x1e/0x30 > [ 234.305938] ? syscall_return_slowpath+0x13c/0x1c0 > [ 234.306746] ? prepare_exit_to_usermode+0xdb/0x140 > [ 234.307530] ? syscall_trace_enter+0x330/0x330 > [ 234.308198] ? __put_user_4+0x1c/0x30 > [ 234.308738] entry_SYSCALL_64_after_hwframe+0x44/0xa9 > [ 234.309477] RIP: 0033:0x7fb9b45fc229 > [ 234.310007] RSP: 002b:00007ffeedbd29a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000089 > [ 234.311068] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fb9b45fc229 > [ 234.312105] RDX: 4400d4d4d4d4d4d4 RSI: 00007fb9b4b98000 RDI: 0000558bf5900d90 > [ 234.313179] RBP: 00007fb9b4caf000 R08: 0000000000000000 R09: 0036363636363636 > [ 234.314146] R10: 00000000000000b8 R11: 0000000000000246 R12: 0000000000000089 > [ 234.315127] R13: 00007fb9b4caf048 R14: 00007fb9b4cd9ad8 R15: 00007fb9b4caf000 > > [ 234.316370] Allocated by task 130: > [ 234.316945] __kmalloc+0x124/0x210 > [ 234.317484] ceph_monmap_decode+0x1c1/0x400 > [ 234.318008] dispatch+0x113/0xd20 > [ 234.318380] ceph_con_workfn+0xa7e/0x44e0 > [ 234.318837] process_one_work+0x5f0/0xa30 > [ 234.319296] worker_thread+0x184/0xa70 > [ 234.319715] kthread+0x1a0/0x1c0 > [ 234.320083] ret_from_fork+0x35/0x40 > > [ 234.320676] Freed by task 130: > [ 234.321039] kfree+0xb8/0x210 > [ 234.321385] dispatch+0x15a/0xd20 > [ 234.321766] ceph_con_workfn+0xa7e/0x44e0 > [ 234.322244] process_one_work+0x5f0/0xa30 > [ 234.322668] worker_thread+0x184/0xa70 > [ 234.323067] kthread+0x1a0/0x1c0 > [ 234.323531] ret_from_fork+0x35/0x40 > > [ 234.324401] The buggy address belongs to the object at ffff88006844f2e0 > which belongs to the cache kmalloc-192 of size 192 > [ 234.325786] The buggy address is located 0 bytes inside of > 192-byte region [ffff88006844f2e0, ffff88006844f3a0) > [ 234.326876] The buggy address belongs to the page: > [ 234.327576] page:ffffea0001a11380 count:1 mapcount:0 mapping:0000000000000000 index:0x0 compound_mapcount: 0 > [ 234.329493] flags: 0x4000000000008100(slab|head) > [ 234.330396] raw: 4000000000008100 0000000000000000 0000000000000000 00000001000f000f > [ 234.331882] raw: ffffea0001a4d4a0 ffffea00018a3720 ffff88006d002a40 0000000000000000 > [ 234.332947] page dumped because: kasan: bad access detected > > [ 234.334227] Memory state around the buggy address: > [ 234.335074] ffff88006844f180: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc > [ 234.336296] ffff88006844f200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc > [ 234.337549] >ffff88006844f280: fc fc fc fc fc fc fc fc fc fc fc fc fb fb fb fb > [ 234.338713] ^ > [ 234.339787] ffff88006844f300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb > [ 234.341011] ffff88006844f380: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc > [ 234.342177] ================================================================== > [ 234.343394] Disabling lock debugging due to kernel taint > > Signed-off-by: Luis Henriques > --- > fs/ceph/super.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/fs/ceph/super.c b/fs/ceph/super.c > index b33082e6878f..9c788e59fc04 100644 > --- a/fs/ceph/super.c > +++ b/fs/ceph/super.c > @@ -45,7 +45,7 @@ static void ceph_put_super(struct super_block *s) > static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) > { > struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry)); > - struct ceph_monmap *monmap = fsc->client->monc.monmap; > + struct ceph_mon_client *monc = &fsc->client->monc; > struct ceph_statfs st; > u64 fsid; > int err; > @@ -58,7 +58,7 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) > } > > dout("statfs\n"); > - err = ceph_monc_do_statfs(&fsc->client->monc, data_pool, &st); > + err = ceph_monc_do_statfs(monc, data_pool, &st); > if (err < 0) > return err; > > @@ -94,8 +94,11 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) > buf->f_namelen = NAME_MAX; > > /* Must convert the fsid, for consistent values across arches */ > - fsid = le64_to_cpu(*(__le64 *)(&monmap->fsid)) ^ > - le64_to_cpu(*((__le64 *)&monmap->fsid + 1)); > + mutex_lock(&monc->mutex); > + fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^ > + le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1)); > + mutex_unlock(&monc->mutex); > + > buf->f_fsid.val[0] = fsid & 0xffffffff; > buf->f_fsid.val[1] = fsid >> 32; > Applied, thanks Yan, Zheng > -- > To unsubscribe from this list: send the line "unsubscribe ceph-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html