Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6609161ybl; Mon, 23 Dec 2019 08:38:08 -0800 (PST) X-Google-Smtp-Source: APXvYqydSoq5bx0V+DM+B49RK+UN/WEUS2ZMA2qaLnFzeLr+pgsYlOY0DNsvwB8TH2gOVjq2R+YS X-Received: by 2002:a9d:588c:: with SMTP id x12mr32369508otg.2.1577119088923; Mon, 23 Dec 2019 08:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577119088; cv=none; d=google.com; s=arc-20160816; b=dm4itCRoRknEghXpJA1ZhxJS4Z90MFOQ0ph0jBsTS8BGpR9R69qVTZY9AIDu1xB9vg b+26fSkSmi6cJnT2ERZXfwayu6fR5w4UqXsz9pdBIVkMsyJMQp53RJRdIG8XPrXAYKqw GqMxX0wwxNTpgJLR/d9QnjIj2N7EkhqH1RVyFjLO02cjmrFK6fO9s88oQW0l2zUCHIwL Crp2Vu00Tk3Kc8nrVwi7Zu7fDdwUSq37FDTV0slFgQt8Qu3qDOYvAeJ+uXSCRfqvZl6M +clwS0VLSKD0Usq+/1dVb+Ey8LdV93E6b0fWSoN4jUMQHesqXe18A128PzkurqxxjU9E ipLA== 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; bh=DMCgPncuWHJTD5/ks/DMMUA1VLzNBNuj3082cj/3jJ0=; b=oaBnKxAWl1+Rv6vLhCHbjy1UwW62L085D7lSGtc/R+CpQk/daVE8YSZ/bbBiqd4/eP 6gbiDKYgR7zBhfeySp9ZUbK1O95GBm5DXWDh0J2PZtleoHeK8dg+Q3mrdOo81fxRO6QS /0rW1bC1To9pRpjBd8MPWW6AEv5o50XYb3ZauXO5R5X61auuKM2nM5dyYDAHrglwa+eQ urvzgRX2uAhQeoftMzXypN1JfL+bCPpTQCbisAcdlqQ02ybNZeX8+1NHJlkKsJFYxUnD 3mxAYGgNp5EBhNyQLmCFuGvRJN/ewOS2LIO3C5rHthiYXYfdsljs6BEdWgy4Ea43QHVj qMxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="da18x/ct"; 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 i25si9497284oii.259.2019.12.23.08.37.56; Mon, 23 Dec 2019 08:38:08 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b="da18x/ct"; 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 S1726976AbfLWQgN (ORCPT + 99 others); Mon, 23 Dec 2019 11:36:13 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40506 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbfLWQgM (ORCPT ); Mon, 23 Dec 2019 11:36:12 -0500 Received: by mail-pl1-f195.google.com with SMTP id s21so4643543plr.7 for ; Mon, 23 Dec 2019 08:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DMCgPncuWHJTD5/ks/DMMUA1VLzNBNuj3082cj/3jJ0=; b=da18x/ctAjwsEUbMO0otQqgpJkCE/Gh0u74KFUbz3wbU075YHtnUrn3rCxSSgeHa1g Hs4gFA8AiPsK0IYN65u6SsuiTmGL5mzklIcZcmhQA5dJuVmkIHylF2tXtvE9mmyZ7j2I 0dGsXwEcOSxD+KhvWPQlakT5NQfaqSgLWTuz8OSob9Ac1LBbhj8JPZ4/joqbxLh/yDlQ BH5s9P6bWFsZcExGutsbyoknm6wgvQwRASZ60TF2wJ4LcrREEVX5geSkCnuUibFwaMMj QKAFainxLQymSMjYlbkRLzZs9h/ZYX3l+AsHxRSy9SQ+lqrOkK8+oj21fSA9HJwU1nSN 07DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=DMCgPncuWHJTD5/ks/DMMUA1VLzNBNuj3082cj/3jJ0=; b=T5WjfYh4qOTmkl1pABx396bOfhxrRCswSMI+L7degSEbONqlFPK9eWv9ef8bdNLaH/ atxilGyMeq5A2JAVWgXJbtmL0ZWLCdrECOQUSmboSSig3QaGM3wKlYtQv74NUZ8xoUd4 2+S4KA1+RmDx2NScl5zYkNUAV5xsrhCPwHyxMiqDpOGYgc9Q4iw0rIJ7dbRJu8TXb5ck Lffw75KP1swF1xjPcOMiCSBjK68JjXY+E5I1alQVlx6UEcnRgxV+1hud3rSiYLtlbkVn GZpBBxLyTpsM9vyAfqjQMpxdtyWs0hsz2HzRJjgX77BJsKJe31O1gkkZgRQDwrf7cy0p 9MEQ== X-Gm-Message-State: APjAAAWpRz8VE3uPdySrKsqfDzYLru9Yqcg8LfSeQwGVpTstCtU1qt8V Su1Wq+scpINRSHzkRnKq1gEaXTve X-Received: by 2002:a17:902:421:: with SMTP id 30mr32012017ple.324.1577118972115; Mon, 23 Dec 2019 08:36:12 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id z13sm21636768pjz.15.2019.12.23.08.36.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Dec 2019 08:36:11 -0800 (PST) Date: Mon, 23 Dec 2019 08:36:10 -0800 From: Guenter Roeck To: Daniel Axtens Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, akash.goel@intel.com, ajd@linux.ibm.com, syzbot+1e925b4b836afe85a1c6@syzkaller-ppc64.appspotmail.com, syzbot+587b2421926808309d21@syzkaller-ppc64.appspotmail.com, syzbot+58320b7171734bf79d26@syzkaller.appspotmail.com, syzbot+d6074fb08bdb2e010520@syzkaller.appspotmail.com Subject: Re: [PATCH] relay: handle alloc_percpu returning NULL in relay_open Message-ID: <20191223163610.GA32267@roeck-us.net> References: <20191129013745.7168-1-dja@axtens.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191129013745.7168-1-dja@axtens.net> 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 Fri, Nov 29, 2019 at 12:37:45PM +1100, Daniel Axtens wrote: > alloc_percpu() may return NULL, which means chan->buf may be set to > NULL. In that case, when we do *per_cpu_ptr(chan->buf, ...), we > dereference an invalid pointer: > > BUG: Unable to handle kernel data access at 0x7dae0000 > Faulting instruction address: 0xc0000000003f3fec > ... > NIP [c0000000003f3fec] relay_open+0x29c/0x600 > LR [c0000000003f3fc0] relay_open+0x270/0x600 > Call Trace: > [c000000054353a70] [c0000000003f3fb4] relay_open+0x264/0x600 (unreliable) > [c000000054353b00] [c000000000451764] __blk_trace_setup+0x254/0x600 > [c000000054353bb0] [c000000000451b78] blk_trace_setup+0x68/0xa0 > [c000000054353c10] [c0000000010da77c] sg_ioctl+0x7bc/0x2e80 > [c000000054353cd0] [c000000000758cbc] do_vfs_ioctl+0x13c/0x1300 > [c000000054353d90] [c000000000759f14] ksys_ioctl+0x94/0x130 > [c000000054353de0] [c000000000759ff8] sys_ioctl+0x48/0xb0 > [c000000054353e20] [c00000000000bcd0] system_call+0x5c/0x68 > > Check if alloc_percpu returns NULL. Because we can readily catch and > handle this situation, switch to alloc_cpu_gfp and pass in __GFP_NOWARN. > > This was found by syzkaller both on x86 and powerpc, and the reproducer > it found on powerpc is capable of hitting the issue as an unprivileged > user. > > Fixes: 017c59c042d0 ("relay: Use per CPU constructs for the relay channel buffer pointers") > Reported-by: syzbot+1e925b4b836afe85a1c6@syzkaller-ppc64.appspotmail.com > Reported-by: syzbot+587b2421926808309d21@syzkaller-ppc64.appspotmail.com > Reported-by: syzbot+58320b7171734bf79d26@syzkaller.appspotmail.com > Reported-by: syzbot+d6074fb08bdb2e010520@syzkaller.appspotmail.com > Cc: Akash Goel > Cc: Andrew Donnellan # syzkaller-ppc64 > Cc: stable@vger.kernel.org # v4.10+ > Signed-off-by: Daniel Axtens > So there is a CVE now, but it appears that the patch went nowhere. Are there any plans to actually apply it ? Thanks, Guenter > -- > > There's a syz reproducer on the powerpc syzbot that eventually hits > the bug, but it can take up to an hour or so before it keels over on a > kernel with all the syzkaller debugging on, and even longer on a > production kernel. I have been able to reproduce it once on a stock > Ubuntu 5.0 ppc64le kernel. > > I will ask MITRE for a CVE - while only the process doing the syscall > gets killed, it gets killed while holding the relay_channels_mutex, > so it blocks all future relay activity. > --- > kernel/relay.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/kernel/relay.c b/kernel/relay.c > index ade14fb7ce2e..a376cc6b54ec 100644 > --- a/kernel/relay.c > +++ b/kernel/relay.c > @@ -580,7 +580,13 @@ struct rchan *relay_open(const char *base_filename, > if (!chan) > return NULL; > > - chan->buf = alloc_percpu(struct rchan_buf *); > + chan->buf = alloc_percpu_gfp(struct rchan_buf *, > + GFP_KERNEL | __GFP_NOWARN); > + if (!chan->buf) { > + kfree(chan); > + return NULL; > + } > + > chan->version = RELAYFS_CHANNEL_VERSION; > chan->n_subbufs = n_subbufs; > chan->subbuf_size = subbuf_size; > -- > 2.20.1 >