Received: by 10.213.65.68 with SMTP id h4csp893482imn; Wed, 4 Apr 2018 09:01:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx49vJEdpvSnQa41y6kz2Rg53P2NQYsLi6qAR5ly1va/BK24odHfGn3UU/qt5zfOxy9WI+XrJ X-Received: by 10.98.34.3 with SMTP id i3mr12740759pfi.203.1522857675886; Wed, 04 Apr 2018 09:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522857675; cv=none; d=google.com; s=arc-20160816; b=MDTsAwxPtFP7x7vC6hxfZsmKQJvLUlJSQVSIs+n0OzmFYC5m1rG4BJQdacKieR0Ioj 6WiXKN2TDYdg0fTd6Fxc2D54AFx7Nh4k1Zl0uYQuWl7HrU7TUC6dkdAU+jgLakunHBm7 9GBlPgNoxyrGHlVcen5Dq3GIsArrCvXbVp0yqpkpl1W+6Y0PR3fFOb0ZGRH5m1IwJjmd rBGKsfKibgbO9OvSmRD5BVL3pHBIG3c1+PBWpY74LlqoALwS/vluZUMw8HY2JsUtK3ee vsoHn6muBnBsOwULT04RuVibQOOIf2yZOY7spPNWCN1g1nHZo+I2J4tO/rrwxN3FEuMa DdIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:message-id:in-reply-to :references:from:subject:cc:to:arc-authentication-results; bh=pxXryoQS1SK4kERXudzQ/b0ZonHmfsUsB6jbz+8kLRM=; b=txV/4nPhKvAcCMDD1l+NwFJvrkuJytN90BRqw6jmZOxypJWnYUoliArw30uOkghHo8 3HVIXif1L7ZnZoKo8B0xrVlbAqIFB8cmz8/4e/Hz6srz1NC4q5kDard8l0ZJbydHxwrM dgVCapB5pcDHlsN4LXvSVZlgtnjBi75rZgffTbp5bJJ7fU602JF+/8BxJPSpdUIAj3pS PqSO7IiwD3DjLB1m9mWQPWhNFNEsnbHP57/7KtwxRCGvXKTTP6TscXcDyRM8u7EAL89H 0mLitaF3zRVK6biCfJBoJfnHf4/qPL80xR1M3BM507CRvnEzkl4L/XLkUmC9h7UeORNT Vzfw== ARC-Authentication-Results: i=1; mx.google.com; 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 o1-v6si3326379plb.459.2018.04.04.09.01.01; Wed, 04 Apr 2018 09:01:15 -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; 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 S1752276AbeDDP7U (ORCPT + 99 others); Wed, 4 Apr 2018 11:59:20 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:24262 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751582AbeDDP7T (ORCPT ); Wed, 4 Apr 2018 11:59:19 -0400 Received: from fsav103.sakura.ne.jp (fsav103.sakura.ne.jp [27.133.134.230]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w34Fwrqv066949; Thu, 5 Apr 2018 00:58:53 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav103.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav103.sakura.ne.jp); Thu, 05 Apr 2018 00:58:53 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav103.sakura.ne.jp) Received: from AQUA (softbank126099184120.bbtec.net [126.99.184.120]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w34FwqL8066944; Thu, 5 Apr 2018 00:58:52 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: ynorov@caviumnetworks.com Cc: syzbot+6887cbb011c8054e8a3d@syzkaller.appspotmail.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lizefan@huawei.com, syzkaller-bugs@googlegroups.com, noamca@mellanox.com, linux@rasmusvillemoes.dk, mawilcox@microsoft.com, mchehab@kernel.org, akpm@linux-foundation.org Subject: Re: INFO: rcu detected stall in bitmap_parselist From: Tetsuo Handa References: <000000000000edc3690568cc95eb@google.com> <20180404154136.p7aeye7657q466sq@yury-thinkpad> In-Reply-To: <20180404154136.p7aeye7657q466sq@yury-thinkpad> Message-Id: <201804050058.EIB64593.LtSFQHFJOMOVFO@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Thu, 5 Apr 2018 00:58:46 +0900 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yury Norov wrote: > Hi Tetsuo, > > Thanks for the patch. > > On Wed, Apr 04, 2018 at 09:21:43PM +0900, Tetsuo Handa wrote: > > Yury, are you OK with this patch? > > > > > > >From 7f21827cdfe9780b4949b22bcd19efa721b463d2 Mon Sep 17 00:00:00 2001 > > From: Tetsuo Handa > > Date: Wed, 4 Apr 2018 21:12:10 +0900 > > Subject: [PATCH] lib/bitmap: Rewrite __bitmap_parselist(). > > > > syzbot is catching stalls at __bitmap_parselist() [1]. The trigger is > > > > unsigned long v = 0; > > bitmap_parselist("7:,", &v, BITS_PER_LONG); > > Could you add this case to the test_bitmap_parselist()? > > > which results in hitting infinite loop at > > > > while (a <= b) { > > off = min(b - a + 1, used_size); > > bitmap_set(maskp, a, off); > > a += group_size; > > } > > > > due to used_size == group_size == 0. > > > > Current code is difficult to read due to too many flag variables. > > Let's rewrite it. > > I also don't like current implementation of bitmap_parselist(), but > discussion on new code may take some time. Can you submit minimal > fix in separated patch to let people discuss your new implementation > without rush? OK. Then you can write the patch. You know current code better than I. > > @@ -485,6 +485,58 @@ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, > > } > > EXPORT_SYMBOL(bitmap_print_to_pagebuf); > > > > +static bool get_uint(const char **buf, unsigned int *res) > > +{ > > + const char *p = *buf; > > + > > + if (!isdigit(*p)) > > + return false; > > + *res = simple_strtoul(p, (char **) buf, 10); > > In comment to simple_strtoul(): "This function is obsolete. Please > use kstrtoul instead." I intentionally choose simple_strtoul() because next delimiter (e.g. '-') starts at returned address. kstrtoul() fails if next letter starts. > > > + return p < *buf; I think I should limit to "0 <= *res <= INT_MAX" range in order to avoid overflow at start += group_size. > > +} > > + > > +static int __bitmap_parse_one_chunk(const char *buf, unsigned long *maskp, > > + const unsigned int nmaskbits) > > +{ > > + unsigned int start; > > + unsigned int end; > > + unsigned int group_size; > > + unsigned int used_size; > > + > > + while (*buf && isspace(*buf)) > > + buf++; > > + if (!get_uint(&buf, &start)) > > + return -EINVAL; > > + if (*buf == '-') { > > + buf++; > > + if (!get_uint(&buf, &end) || start > end) > > + return -EINVAL; > > + if (*buf == ':') { > > + buf++; > > + if (!get_uint(&buf, &used_size) || *buf++ != '/' || > > + !get_uint(&buf, &group_size) || > > + used_size > group_size) > > + return -EINVAL; > > So this is still not safe against "1-10:0/0", or I miss something? > (This is another testcase we should add to test_bitmap.c) Indeed. We need to make more testcases. > > + while (buflen && !err) { > > + char *cp; > > + char tmpbuf[256]; > > + unsigned int size = min(buflen, > > + (unsigned int) sizeof(tmpbuf) - 1); > > + > > + if (!is_user) > > + memcpy(tmpbuf, buf, size); > > + else if (copy_from_user(tmpbuf, (const char __user __force *) > > + buf, size)) > > + return -EFAULT; > > This is not safe against this: > "[250 whitespaces] 567-890:123/456" Do we need to accept such insane entry? > > And it will be Schlemiel the painter's-styled algorithm for input like: > "1,2,3,4, ... ,98,99,100". > > I think we need something like __bitmap_parse_get_chunk() to copy > coma-separated substrings.