Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1377748pxk; Mon, 31 Aug 2020 18:21:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWJFZt0reL6dMg4rJZ1oBAJbeBWDu97O/SPLMSMa0wWIDOWD+APaRxiCDhPMI2aWkjX9pU X-Received: by 2002:aa7:ca4f:: with SMTP id j15mr3559771edt.378.1598923296144; Mon, 31 Aug 2020 18:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598923296; cv=none; d=google.com; s=arc-20160816; b=Z4flvmtis9u+QW5fV80nC8lupVqnxl68spgaGNdcC5BU4yMjyN4/Zjb+aMxMlL8zYy WGDHS7+gQ2ciP7nLFGYjVLSsan844CPm1nL0p2TsxgjHi+QhJiEvqmu81wM0SVcG52fG RKHqUZ+V8LXk2fYY6pEmLcMeiYp5xkqXQDBo8HHyucqJpiLlLwVszcrljilsLFgEb8PA UOKsRO/kD4DudFBBY4Mm5xmqaFT+2rVvJ1oEkhiJXLDFD6H0cQ8/i09ssWiguXqdWjJG bX92ZNwOGqX/ubjQcR9BgaPKheZyoiHl+/EURaQyEkOvF4ran3yEQc2hH1IAXktcI0K4 Ahrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=y7U4YcbylZBpyJ3yH6rFWdJSbPInXbwLt1azlfiFuPY=; b=s6jUz3MkTkTZrjI20ZDbHfxIaPY8DfGrO9t/qQME2tutHUZHVJ9gWZlVecB1C6vKob +6YkcrLCikYatanlnjVhqbT3JR+u7EFPKnG47/UFo3ujN3vEyjtGZImm4kmDvYji+BYe /fXIeUMXfHVAezpiQww8Ns0q2ZVUZkAT5XzUp/+aSegSEK80YUyNInCK45jnmhF1Ie3g 4hPRO3I/ICBcIrCRpOs8EVQI8GUk3LiMJGy7BatDm4Oo+PqQkUALAvhOFtl2taT931E5 OigCexHJObAehtTkFm9JJihY+MJ1CpwO4zJO/jogCgyerO1FtnYsULdVBzN/zPrFqGje 1NmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm1 header.b="RJyg9Fa/"; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=QOXH1VRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g27si5917078ejb.556.2020.08.31.18.21.13; Mon, 31 Aug 2020 18:21:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm1 header.b="RJyg9Fa/"; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=QOXH1VRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726023AbgIABRU (ORCPT + 99 others); Mon, 31 Aug 2020 21:17:20 -0400 Received: from wnew2-smtp.messagingengine.com ([64.147.123.27]:46375 "EHLO wnew2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgIABPu (ORCPT ); Mon, 31 Aug 2020 21:15:50 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id A1C70E2F; Mon, 31 Aug 2020 21:15:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 31 Aug 2020 21:15:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=y7U4YcbylZBpyJ3yH6rFWdJSbPI nXbwLt1azlfiFuPY=; b=RJyg9Fa/m9dXWn7xAH4H6BdFRqPhj/UeUVcImUIGmg6 F2wjTEspoU9IC0ivriSOPZ5cnkMpCLcB6oquJgp/PT8woAxBAEt69rlrP06Ke7Jr WeroN+VfKFnj9pwpDTkxrMpGIqa5APDgo8HFu91Rl8PeDasLtfBYAz7AYKpQyvhJ aO+iKqlRRfjI1kQpc2gzdNbGatVol/J9HdBpxaxrY8JqUxOh5v+FOaWOzjXoxnTJ 8Jh8aIrRaqEXixsH+0Vs2TADrCJuMxUO0KBsyUo28UeMxh8dvAN87CwB5xWjVCye 7R1qgUSiQ/x2bBAapCnKxtJHzgFeCDfkKK8drDxHcDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=y7U4Yc bylZBpyJ3yH6rFWdJSbPInXbwLt1azlfiFuPY=; b=QOXH1VRqSaB5EZV6qhgfTa Ti3ngCuTN+orkAc9TDnxwwWvKov7KhiKmR7iSTcNfEzkEC8oRvWdnq8EhaU9WT/A CXOu8ij6jUzrgOil2v5kObsmBbE3nRmG5CmMbOFlMmnfcRcKnDVHx1EeksPehl0w pNir7ibhO4Y8fXuM6Bof0zqU7xpk0n9OskI5Ehc+RURXBkhGJhzWKBkEU1Iz5D61 waFhPum/blR4tKAEM8EKkiJlRoFocfQoBHdfIQVFuG+NP2U2KiBHVhB/HpWkWkrR rMXxxQOiMbzmabTJrGgOHmGdKDXmgAWkYVKHPdZFNx8+ZTgYKsBjPwC1pvwzoATA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudefiedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepfffhvffukfhfgggtuggj sehttdertddttddvnecuhfhrohhmpefvhigthhhoucetnhguvghrshgvnhcuoehthigthh hosehthigthhhordhpihiiiigrqeenucggtffrrghtthgvrhhnpeffieegtdfhudeiveef iedtveevgeevhfejfeduieeivedvveetgfeuveejkeffudenucffohhmrghinheprghpph hsphhothdrtghomhenucfkphepuddvkedruddtjedrvdeguddrudekfeenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthigthhhosehthigthh hordhpihiiiigr X-ME-Proxy: Received: from cisco (unknown [128.107.241.183]) by mail.messagingengine.com (Postfix) with ESMTPA id 56FC83280064; Mon, 31 Aug 2020 21:15:01 -0400 (EDT) Date: Mon, 31 Aug 2020 19:14:59 -0600 From: Tycho Andersen To: Kees Cook Cc: Christian Brauner , linux-kernel@vger.kernel.org, luto@amacapital.net, syzbot , syzkaller-bugs@googlegroups.com, wad@chromium.org Subject: Re: memory leak in do_seccomp Message-ID: <20200901011459.GA583718@cisco> References: <000000000000e5ea9e05ac9d16c1@google.com> <000000000000df80ae05ae244c2b@google.com> <202008311620.AC4A7047D@keescook> <20200901000915.GA564594@cisco> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200901000915.GA564594@cisco> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 31, 2020 at 06:09:15PM -0600, Tycho Andersen wrote: > On Mon, Aug 31, 2020 at 04:25:35PM -0700, Kees Cook wrote: > > On Sun, Aug 30, 2020 at 08:50:15PM -0700, syzbot wrote: > > > syzbot has found a reproducer for the following issue on: > > > > > > HEAD commit: dcc5c6f0 Merge tag 'x86-urgent-2020-08-30' of git://git.ke.. > > > git tree: upstream > > > console output: https://syzkaller.appspot.com/x/log.txt?x=10b297d5900000 > > > kernel config: https://syzkaller.appspot.com/x/.config?x=903b9fecc3c6d231 > > > dashboard link: https://syzkaller.appspot.com/bug?extid=3ad9614a12f80994c32e > > > compiler: gcc (GCC) 10.1.0-syz 20200507 > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14649561900000 > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=118aacc1900000 > > > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > > Reported-by: syzbot+3ad9614a12f80994c32e@syzkaller.appspotmail.com > > > > > > executing program > > > executing program > > > executing program > > > executing program > > > executing program > > > BUG: memory leak > > > unreferenced object 0xffff88811ba93600 (size 64): > > > comm "syz-executor680", pid 6503, jiffies 4294951104 (age 21.940s) > > > hex dump (first 32 bytes): > > > 00 00 00 00 00 00 00 00 08 36 a9 1b 81 88 ff ff .........6...... > > > 08 36 a9 1b 81 88 ff ff 11 ce 98 89 3a d5 b4 8f .6..........:... > > > backtrace: > > > [<00000000896418b0>] kmalloc include/linux/slab.h:554 [inline] > > > [<00000000896418b0>] kzalloc include/linux/slab.h:666 [inline] > > > [<00000000896418b0>] init_listener kernel/seccomp.c:1473 [inline] > > > [<00000000896418b0>] seccomp_set_mode_filter kernel/seccomp.c:1546 [inline] > > > [<00000000896418b0>] do_seccomp+0x8ce/0xd40 kernel/seccomp.c:1649 > > > [<000000002b04976c>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 > > > [<00000000322b4126>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > > I haven't narrowed this down yet (and it *might* be a false positive), > > but it looks like this is filter->notif. The only way that's possible is > > if seccomp_notify_release() was never called *and* seccomp_filter_free() > > got called... which would imply a reference counting problem. The way > > there doesn't jump out at me yet, but I haven't yet decoded the C > > reproducer into the actual seccomp arguments, etc. > > Looks like it's just a bunch of threads in the same thread group > trying to install a filter with TSYNC and NEW_LISTENER turned on. Does > the patch below look reasonable? > > I didn't send it separately since I'm in the process of switching my > e-mail address to tycho@tycho.pizza; let this e-mail serve as proof > that that e-mail really is me too :). I can send it the normal way if > it looks good. > > > From d497e787e8e1b3e8b9230fdc4c9802616709c920 Mon Sep 17 00:00:00 2001 > From: Tycho Andersen > Date: Mon, 31 Aug 2020 17:55:07 -0600 > Subject: [PATCH] seccomp: don't leak memory when filter install races > > In seccomp_set_mode_filter() with TSYNC | NEW_LISTENER, we first initialize > the listener fd, then check to see if we can actually use it later in > seccomp_may_assign_mode(), which can fail if anyone else in our thread > group has installed a filter and caused some divergence. If we can't, we > partially clean up the newly allocated file: we put the fd, put the file, > but don't actually clean up the *memory* that was allocated at > filter->notif. Let's clean that up too. > > Fixes: 51891498f2da ("seccomp: allow TSYNC and USER_NOTIF together") > Reported-by: syzbot+3ad9614a12f80994c32e@syzkaller.appspotmail.com > Signed-off-by: Tycho Andersen > --- > kernel/seccomp.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/seccomp.c b/kernel/seccomp.c > index 3ee59ce0a323..21a76127833f 100644 > --- a/kernel/seccomp.c > +++ b/kernel/seccomp.c > @@ -1581,6 +1581,8 @@ static long seccomp_set_mode_filter(unsigned int flags, > listener_f->private_data = NULL; > fput(listener_f); > put_unused_fd(listener); > + kfree(filter->notif); > + filter->notif = NULL; Oof, actually this isn't quite right. It should be s/filter/prepared/g. I can fix that and send out a real patch that's actually tested at some point tomorrow. Tycho