Received: by 10.213.65.16 with SMTP id m16csp64798imf; Sun, 11 Mar 2018 15:36:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELsJlIpO/ZpH1VyTPQF/osmkOMDm/uh3fqKfZGJzv9SRPfkyn+fQFYG5P+ln2q9WboDSzTw2 X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr5927120plk.362.1520807788295; Sun, 11 Mar 2018 15:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520807788; cv=none; d=google.com; s=arc-20160816; b=fDcOm9NnbKiJdManWdbrTrv1acCf3eTnNoXnYtI332Garzbtxh/1rZfm/CoiuUbucM 8mtEb6JXh6tL+lsc3rwLs2kKALUl9KDa0k/QJprBgUHIsv/dX3aAWKkeZnRjX17ZlXs7 pXA9aqooxnXC1T7pI3ha081Bhvy4fdGYZtcX3XJ4LYNjOIpfxgISy9D+gJiurkX7faRf jFlx2fa1V7TcKb2lbKTIW92YF/CwCG9dCO5L7W8/yzGheWu3KnyQ/HQspZu8FVkFiDhb WV1QwKFXcgqme9MTfNd6VDi12lvbWKNcio/dfvp/VTVf+syTSvfiVEMkaO7etc8IlXGT i1fw== 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=f9GIEtL6z3YXNKxL4Z1/5VS2p5795s9oRf/xPuj9nUI=; b=zrxASsU0/Jnv+0x2JbIxtERwZE/X5k9dHNnb9L6TeiBv5eT83bOTGSF132fuCC/hRN QXsCa6HZx2OgLUeJxnVfyIcJFLVR4nSvsC9RG65RYl2lNAIRAjGS6cZSYFykm3JuHW1a erXCXul2xWJg7VGK41WYfb4UrzHIROwWUHFaHA2+4irUP26wxTaCrzsYVmGnk0N7MnpY XO1bdgpCUTJb3hifFN6WcT9x6N4i1mgFmJ78uK+Yzx/un/8ue81d7UfTw3ycY4JGAIB9 2K52F5PrJha0jeqe2K7u8WgAvrmW2FzjPIDDcpCvpJl0T+si2n8bZ/MTnMKDllU0mwr9 98oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quantonium-net.20150623.gappssmtp.com header.s=20150623 header.b=hE0RwF9H; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8-v6si4891279ple.435.2018.03.11.15.36.13; Sun, 11 Mar 2018 15:36:28 -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=@quantonium-net.20150623.gappssmtp.com header.s=20150623 header.b=hE0RwF9H; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932528AbeCKWfW (ORCPT + 99 others); Sun, 11 Mar 2018 18:35:22 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:36285 "EHLO mail-wr0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932347AbeCKWfU (ORCPT ); Sun, 11 Mar 2018 18:35:20 -0400 Received: by mail-wr0-f176.google.com with SMTP id d10so1392244wrf.3 for ; Sun, 11 Mar 2018 15:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantonium-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=f9GIEtL6z3YXNKxL4Z1/5VS2p5795s9oRf/xPuj9nUI=; b=hE0RwF9H2owCLbkBgHMmHcNlOeYaXTcKPVeze+s4csMxdeePpuznnVA870ibz5P1Sc MyngnAPu4LMO4at42lM2WbaNn+mmaMY0PDZihQoL1Jdz4ylu4YBqxWHYUIcdggjW/bo4 YWMbhqUpF66foDHeKp41A/2Tup0E8umJvAOPhUolF9xv0u1wvQVaAI+W7avUnrwTetZG pwerA08vQ2PJw4rFrMNDxW/Z77ibV0P7NXaQq+5Qq31IiMkKD+LmbMze+ktzUpzghkfx THsuGUZ6+pOggplkdEr0pT7jDJq0Ck7CjTRs5LbXHeGsj5HLUtfhTGe2HWl7RnreACZ0 l9yA== 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=f9GIEtL6z3YXNKxL4Z1/5VS2p5795s9oRf/xPuj9nUI=; b=JWUJYdKlsn0tOzZx90Jdkux6Pi9wt0/sCXcHUIYL2UmGpOoYI3smBXMeUWdGNyl7oQ cTj4r7BXF2JfLEEYSZbtjvVznSyabGbRXQAfakTFRMyDdO10I3LRJ9DNmcw1y+Di5N0+ GhLUyFdA1UpcRVH+RCNfvE6SE+7JaWemhCZQTK8Ia+ynMksApXRMUK0sMdxqsE47vGHI z4NfQOJ6PmZeBIcqRPqTnWhMHZOJFAMm7RoZT2QL7KMAqWfYEBYjsi6oN3KUiSPcdaoL owCK4XKss++Zs8V1SYAktSK53h0WUp2NcCaZLeuBlzwi2uBok4A0+nPSLp8bGtp69Wd+ R8fw== X-Gm-Message-State: AElRT7F2qw8IlU7GEScbZ8u5y4UiCBLNnMZuXGchAzLRgUKAw7Ba/ShT tUfFWBWtutv+pb2B+ApR1nu3XLfkI58JQgIwGyvVuw== X-Received: by 10.223.191.10 with SMTP id p10mr4812001wrh.160.1520807719527; Sun, 11 Mar 2018 15:35:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.135.74 with HTTP; Sun, 11 Mar 2018 15:35:19 -0700 (PDT) In-Reply-To: <20180311213402.GA2267@zzz.localdomain> References: <089e0825d42484310b055c75c3f6@google.com> <20171026175847.GH59538@devbig577.frc2.facebook.com> <20180311213402.GA2267@zzz.localdomain> From: Tom Herbert Date: Sun, 11 Mar 2018 15:35:19 -0700 Message-ID: Subject: Re: KASAN: use-after-free Read in get_work_pool To: Eric Biggers Cc: Cong Wang , Tejun Heo , syzbot , Lai Jiangshan , LKML , Dmitry Vyukov , syzkaller-bugs@googlegroups.com, David Miller , Eric Dumazet , Eric Biggers , netdev 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 Sun, Mar 11, 2018 at 2:34 PM, Eric Biggers wrote: > On Wed, Feb 14, 2018 at 02:45:05PM +0100, 'Dmitry Vyukov' via syzkaller-bugs wrote: >> On Wed, Dec 6, 2017 at 1:50 PM, Dmitry Vyukov wrote: >> > On Fri, Oct 27, 2017 at 11:18 PM, Cong Wang wrote: >> >> On Thu, Oct 26, 2017 at 11:00 PM, Dmitry Vyukov wrote: >> >>> On Thu, Oct 26, 2017 at 7:58 PM, Tejun Heo wrote: >> >>>> Hello, >> >>>> >> >>>> On Thu, Oct 26, 2017 at 09:35:44AM -0700, syzbot wrote: >> >>>>> BUG: KASAN: use-after-free in __read_once_size >> >>>>> include/linux/compiler.h:276 [inline] >> >>>>> BUG: KASAN: use-after-free in atomic64_read >> >>>>> arch/x86/include/asm/atomic64_64.h:21 [inline] >> >>>>> BUG: KASAN: use-after-free in atomic_long_read >> >>>>> include/asm-generic/atomic-long.h:44 [inline] >> >>>>> BUG: KASAN: use-after-free in get_work_pool+0x1c2/0x1e0 >> >>>>> kernel/workqueue.c:709 >> >>>>> Read of size 8 at addr ffff8801cc58c378 by task syz-executor5/21326 >> >>>>> >> >>>>> CPU: 1 PID: 21326 Comm: syz-executor5 Not tainted 4.13.0+ #43 >> >>>>> Hardware name: Google Google Compute Engine/Google Compute Engine, >> >>>>> BIOS Google 01/01/2011 >> >>>>> Call Trace: >> >>>>> __dump_stack lib/dump_stack.c:16 [inline] >> >>>>> dump_stack+0x194/0x257 lib/dump_stack.c:52 >> >>>>> print_address_description+0x73/0x250 mm/kasan/report.c:252 >> >>>>> kasan_report_error mm/kasan/report.c:351 [inline] >> >>>>> kasan_report+0x24e/0x340 mm/kasan/report.c:409 >> >>>>> __asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:430 >> >>>>> __read_once_size include/linux/compiler.h:276 [inline] >> >>>>> atomic64_read arch/x86/include/asm/atomic64_64.h:21 [inline] >> >>>>> atomic_long_read include/asm-generic/atomic-long.h:44 [inline] >> >>>>> get_work_pool+0x1c2/0x1e0 kernel/workqueue.c:709 >> >>>>> __queue_work+0x235/0x1150 kernel/workqueue.c:1401 >> >>>>> queue_work_on+0x16a/0x1c0 kernel/workqueue.c:1486 >> >>>>> queue_work include/linux/workqueue.h:489 [inline] >> >>>>> strp_check_rcv+0x25/0x30 net/strparser/strparser.c:553 >> >>>>> kcm_attach net/kcm/kcmsock.c:1439 [inline] >> >>>>> kcm_attach_ioctl net/kcm/kcmsock.c:1460 [inline] >> >>>>> kcm_ioctl+0x826/0x1610 net/kcm/kcmsock.c:1695 >> >>>>> sock_do_ioctl+0x65/0xb0 net/socket.c:961 >> >>>>> sock_ioctl+0x2c2/0x440 net/socket.c:1058 >> >>>>> vfs_ioctl fs/ioctl.c:45 [inline] >> >>>>> do_vfs_ioctl+0x1b1/0x1530 fs/ioctl.c:685 >> >>>>> SYSC_ioctl fs/ioctl.c:700 [inline] >> >>>>> SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691 >> >>>>> entry_SYSCALL_64_fastpath+0x1f/0xbe >> >>>> >> >>>> Looks like kcm is trying to reuse a work item whose last workqueue has >> >>>> been destroyed without re-initing it. A work item needs to be >> >>>> reinit'd. >> >>> >> >>> +kcm maintainers >> >> >> >> Can you try the fix below? There is no C reproducer so I can't verify it. >> > >> > >> > Hi Cong, >> > >> > syzbot can now test proposed patches, see >> > https://github.com/google/syzkaller/blob/master/docs/syzbot.md#communication-with-syzbot >> > for details. Please give it a try. >> > >> >> diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c >> >> index af4e76ac88ff..7816f44c576a 100644 >> >> --- a/net/kcm/kcmsock.c >> >> +++ b/net/kcm/kcmsock.c >> >> @@ -1433,11 +1433,12 @@ static int kcm_attach(struct socket *sock, >> >> struct socket *csock, >> >> KCM_STATS_INCR(mux->stats.psock_attach); >> >> mux->psocks_cnt++; >> >> psock_now_avail(psock); >> >> - spin_unlock_bh(&mux->lock); >> >> >> >> /* Schedule RX work in case there are already bytes queued */ >> >> strp_check_rcv(&psock->strp); >> >> >> >> + spin_unlock_bh(&mux->lock); >> >> + >> >> return 0; >> >> } >> >> >> Hi Cong, >> >> Was this ever merged? Is it still necessary? >> > > syzbot is no longer hitting this bug for some reason but it's still there. Tom, > it looks like you wrote the buggy code (it's yet another KCM bug, apparently); > can you please look into it? > Yes. Thank you for the simple reproducer. Tom > I've put together a C reproducer that works on latest linux-next (next-20180309, > commit 61530b14b059d). It works as an unprivileged user provided that KCM is > enabled, and that KASAN is enabled so you see the use-after-free report: > > #include > #include > #include > #include > #include > #include > #include > > int main() > { > union bpf_attr prog = { > .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, > .insn_cnt = 2, > .insns = (__u64)(__u64[]){ 0xb7, 0x95 }, > .license = (__u64)"", > }; > int tcp_fd, bpf_fd, kcm_fd; > struct sockaddr_in addr = { > .sin_family = AF_INET, > .sin_port = __constant_htons(3270), > .sin_addr = { __constant_htonl(0x7f000001) } > }; > > tcp_fd = socket(AF_INET, SOCK_STREAM, 0); > bind(tcp_fd, (void *)&addr, sizeof(addr)); > listen(tcp_fd, 1); > tcp_fd = socket(AF_INET, SOCK_STREAM, 0); > connect(tcp_fd, (void *)&addr, sizeof(addr)); > bpf_fd = syscall(__NR_bpf, BPF_PROG_LOAD, &prog, 48); > kcm_fd = socket(AF_KCM, SOCK_SEQPACKET, 0); > if (fork() == 0) { > struct kcm_attach attach = { tcp_fd, bpf_fd }; > > for (;;) > ioctl(kcm_fd, SIOCKCMATTACH, &attach); > } else { > struct kcm_unattach unattach = { tcp_fd }; > > for (;;) > ioctl(kcm_fd, SIOCKCMUNATTACH, &unattach); > } > }