Received: by 10.213.65.16 with SMTP id m16csp48947imf; Sun, 11 Mar 2018 14:35:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELvHcAFufvw0Af73DYnEXMVI7+R4RvbyulYOqGVWpvhJbvROLp7zFJfpYAiCWzaLbM8+gZjw X-Received: by 10.99.120.13 with SMTP id t13mr4862962pgc.35.1520804116417; Sun, 11 Mar 2018 14:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520804116; cv=none; d=google.com; s=arc-20160816; b=gD+ortZKEEWySDFd6WaaE9Twfcln8ImkxdtrxMwsRHvvUwZaKUzHAmiPqsGd2/9ZKi rPuWv0ZP6ksOdHucmr0Ehtfhd6lHB3vNZrqZxoerq7HrRUs4JgkiHHjMqC/i0Ccrq386 bSyD4eBdjyhivSeV5kLtNdZrCfuR6Hgjue0ryEAVnpZTfZDCtPjMuxWe4tzjxBXpxVq5 8L3thjUvNmh/vp0EA18Tv/y5JUU5IbkOmz4E7uSAx9BbVyEkn5ZyBYtOHqYYYSOCI0qO DT8iM9MgFm2DWAPew1sawGoD4vcUjPFrrzuhJe34FIedRC6D/6YJEaPFoq6jw2x8Kb87 nakw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=4hq0xAjyqKWpjXfC0ZuhKEyL0IsViq1LXnbsOnIfCTM=; b=TBHcHSdOeKYHjrj1UxplSSoqpsH6OhJ4tiKRsLuCvKKYXieu0SnRjNljcMklK0MZqo +bi//lVTbUdYGUnkGbfhpOMCHFuA7tErZc3KMwENwK2MxMkGxUwkQntgnrZF7me+FLvg LecoyU5BuJWD8dnVSIVUqjkyLy07Cn6JVn6m7nr9pNNeSy7PGa0SeQy3x3dGbB38qw1K 2vke3P7vWg5Jzs1eSkx3eYa11C+ZmFhDui7H9/GhRG0S/kIB5KPNCj4VmiTZc2KHUhzP wlRxVz6fOaUHcUXG3CpBobqm9DSafnn3DCG4nBD0On1l7XX4E4peKdMoA2GMim1s83L+ WtuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GZp2tzBT; 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 u16-v6si4749650plq.183.2018.03.11.14.35.01; Sun, 11 Mar 2018 14:35:16 -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=GZp2tzBT; 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 S932441AbeCKVeI (ORCPT + 99 others); Sun, 11 Mar 2018 17:34:08 -0400 Received: from mail-pl0-f48.google.com ([209.85.160.48]:40982 "EHLO mail-pl0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932275AbeCKVeG (ORCPT ); Sun, 11 Mar 2018 17:34:06 -0400 Received: by mail-pl0-f48.google.com with SMTP id d9-v6so8216082plo.8; Sun, 11 Mar 2018 14:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4hq0xAjyqKWpjXfC0ZuhKEyL0IsViq1LXnbsOnIfCTM=; b=GZp2tzBT2dJuQLKZWnTeTrk6NDmIfvvFLfmA2N60OVsgM5ihwkWAKpLlNP+iGCFsu5 yyG4MfqCCAMOwpmm6bXqRzKtJyHsRQ/LUg+dROaUB07VP4TGtDoJSKKClnXZmE3MX0P8 cAkzfntNE7rfA6Mo+0TJi+aMpn2Y+b6el7Cy9zfjSov8l7KxDOmvf2VU/YPO95jIab73 eWlx3RfVqgytjJ5TVy7TlZ09zxLdI3KrqDeeTV7jp1w++r93Q4l+5wE0Lj89P31GM6bg gF6rYXLqc6jCPyWHyqtZLl4L4N8j0Bh6ZztcY6TrhBUU/z+37kmCUHkdQN09KAHTfigx 2aYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4hq0xAjyqKWpjXfC0ZuhKEyL0IsViq1LXnbsOnIfCTM=; b=gRE3sdpzhb1cXudTsMeinlxD1k3J2Neg5s0ZKvCOY/4LSLzUEdwx8KbQVrP2UyBHiA zUcreQnEIZ0/AB62jr6MBAOeSAm9MPEQdgTarAblvD7HL6a6tdyEWcuEG2zWS9HalHAA R+ouFdRYf+tAwePNFIyepGuhsvbSGNt3yq4btC3fgSxm8N70st5kP12EERl82p+rGqJQ sEW77k9ZCBziZuz/6MAHoPK3eqmxcRwcRIaNk/P0hWZZlCy7MppsYM5cdUdpXRAdd4FH Ogc7EWGneNLPV9NXBx4yxDi/ubFSFvHyLGKfXXIdYVIfp1mQIDdOe8H0ULhLXma4xWCr 6pCQ== X-Gm-Message-State: AElRT7FlCnyt+AzyYXY19ySj1dfdZZfBbQuWUSexoN3bUQ5raF4dWOJj y/GBYHpJrv7Edq1D3Oqyr/o= X-Received: by 2002:a17:902:9a08:: with SMTP id v8-v6mr5931890plp.252.1520804046141; Sun, 11 Mar 2018 14:34:06 -0700 (PDT) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id s6sm11837017pgn.59.2018.03.11.14.34.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Mar 2018 14:34:04 -0700 (PDT) Date: Sun, 11 Mar 2018 14:34:02 -0700 From: Eric Biggers To: Tom Herbert Cc: Cong Wang , Tejun Heo , syzbot , Lai Jiangshan , LKML , Dmitry Vyukov , syzkaller-bugs@googlegroups.com, David Miller , Eric Dumazet , Eric Biggers , netdev Subject: Re: KASAN: use-after-free Read in get_work_pool Message-ID: <20180311213402.GA2267@zzz.localdomain> References: <089e0825d42484310b055c75c3f6@google.com> <20171026175847.GH59538@devbig577.frc2.facebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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); } }