From patchwork Mon May 7 10:13:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10383827 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B2E3D6037F for ; Mon, 7 May 2018 10:14:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A651328B01 for ; Mon, 7 May 2018 10:14:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9913B28B06; Mon, 7 May 2018 10:14:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 424D428B01 for ; Mon, 7 May 2018 10:14:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751952AbeEGKOI (ORCPT ); Mon, 7 May 2018 06:14:08 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:17423 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751135AbeEGKOH (ORCPT ); Mon, 7 May 2018 06:14:07 -0400 Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w47ADnqm045464; Mon, 7 May 2018 19:13:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Mon, 07 May 2018 19:13:49 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from [192.168.1.8] (softbank126099184120.bbtec.net [126.99.184.120]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w47ADnIB045459 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 7 May 2018 19:13:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Subject: Re: WARNING in add_uevent_var To: Johannes Berg , syzbot , syzkaller-bugs@googlegroups.com References: <000000000000a010b80568d75018@google.com> <1522758845.2961.3.camel@sipsolutions.net> Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org From: Tetsuo Handa Message-ID: <1efbb9dc-e5a0-64d7-da3e-235852783f9c@I-love.SAKURA.ne.jp> Date: Mon, 7 May 2018 19:13:48 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1522758845.2961.3.camel@sipsolutions.net> Content-Language: en-US Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 2018/04/03 21:34, Johannes Berg wrote: > On Sun, 2018-04-01 at 23:01 -0700, syzbot wrote: > >> So far this crash happened 5 times on net-next, upstream. >> C reproducer: https://syzkaller.appspot.com/x/repro.c?id=6614377067184128 >> > > Huh, fun. Looks like you're basically creating a new HWSIM radio with an > insanely long name (4k!) and nothing stops you, until we try to generate > an rfkill instance which sends a uevent and only has a 2k buffer for the > environment variables, where we put the name ... > > But yeah, we should probably limit the phy name to something sane, I'll > pick 128 and send a patch. > I think it should be NAME_MAX. ---------------------------------------- #include #include #include #include #include int main(int argc, char *argv[]) { const int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_GENERIC); static struct { struct nlmsghdr hdr; char data[4120 - sizeof(struct nlmsghdr)]; } buf = { }; struct sockaddr_nl addr = { .nl_family = AF_NETLINK }; struct iovec iov = { &buf, sizeof(buf) }; struct msghdr msg = { .msg_name = &addr, .msg_namelen = sizeof(addr), .msg_iov = &iov, .msg_iovlen = 1, }; buf.hdr.nlmsg_len = 0x1018; buf.hdr.nlmsg_type = 0x22; buf.hdr.nlmsg_flags = 0x109; *(uint8_t*) buf.data = 4; *(uint8_t*) (buf.data + 1) = 0; *(uint16_t*) (buf.data + 2) = 0; *(uint16_t*) (buf.data + 4) = 0x1004; *(uint16_t*) (buf.data + 6) = 0x11; memset(buf.data + 8, 'A', 4096); /* strlen() > NAME_MAX */ sendmsg(fd, &msg, 0); return 0; } ---------------------------------------- From 3eba6541da0c7338e3d71ea83cbc69962923d65e Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Mon, 7 May 2018 15:58:37 +0900 Subject: [PATCH] net: rfkill: Add filename varidity test at rfkill_alloc(). syzbot is hitting WARN() at kobject_uevent_env() [1]. This is because the test case is requesting too long name. Since the name is used as part of pathname under /sys/devices/virtual/ , this name parameter must obey the limitations of a filename. Fix this by applying name validity test to rfkill_alloc(). [1] https://syzkaller.appspot.com/bug?id=c1e1ab1d042b637ee9e25c64b107d51630b9d9ec Signed-off-by: Tetsuo Handa Reported-by: syzbot Cc: Johannes Berg --- net/rfkill/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 59d0eb9..d8beebc 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -933,6 +933,10 @@ struct rfkill * __must_check rfkill_alloc(const char *name, if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES)) return NULL; + if (strlen(name) > NAME_MAX || strchr(name, '/') || + !strcmp(name, ".") || !strcmp(name, "..")) + return NULL; + rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL); if (!rfkill) return NULL;