Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2647484ybk; Mon, 18 May 2020 04:37:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMuUsiz/8Bn/qOtsJVx6MlJMWNgiKgIEEBp/KRVzic9BsjUzN+bf+KTtm06CB+HShJgXqf X-Received: by 2002:a05:6402:2035:: with SMTP id ay21mr12281060edb.279.1589801823842; Mon, 18 May 2020 04:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589801823; cv=none; d=google.com; s=arc-20160816; b=uD/c/SpW7CJ5bnhVqLq1Af8qjgpx+/U6IvIxyGv8QXeyl9MdiDx2B+86izU/IByCBn t8ZCYFCPz/w/R+P5PvxBDgvkmuHX7CfjWTYZ9XDrlBx9se0Cs8jJLP0TOoB0Ef+bdNBB 399Zb4QHzGddYUMySlWZ5xdGzOpC7i6a/xP2344GUVgkvbePNvhTAsXaMi6KJScZ4i9e AiOI1ir/R/YZ8ZSz8AvmcURBrwt4HO5yVxC2R1x5h6GXlgA4OSmdGsWgB7fVjNJi4W0K AQLwYh8q9oY/BQh9A3/Gh+QDw66OVWX6Nf/StsuMylAyljupnoPAm9qH7IpvYeywYHDj ovPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=eJccfybN0sdNJ8ylX53cDwC7dY9jWBu+I0/w3Xw+cBs=; b=cBX8kRmvpms463xAnrRMR615Ux7gETfopZlOSgaqxAI3aL81gB9Rk5y5HeMqOm9f96 HPd6hXxoAIiDQFQiXi+PunSFHEm4w5kPv1iCFz7fEDlI8ygs/2lO4d682sqLF9qfKwOH 3221Bi0n65lZigMrdWpQj7QTRG2DdXPJAzZ6dvJ2O99khQY0QZJervXZOpC1rSc5C6xW ku/c78EY/lkjDniZ9B4Csp+4rIi/cTIXujEEmtEI4Qg1xS+O5sU8N+qJIMm8F7Tg8kcH PMxp7LzFabXGVeqgp2OF0U+cZa5ne1t90vLhqr5bpOczTAmzhzPMT9DXU/Xe00Ifazaf hV3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dhzh1omw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1774542edi.376.2020.05.18.04.36.32; Mon, 18 May 2020 04:37:03 -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=@gmail.com header.s=20161025 header.b=dhzh1omw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726919AbgERLdz (ORCPT + 99 others); Mon, 18 May 2020 07:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgERLdz (ORCPT ); Mon, 18 May 2020 07:33:55 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B1EDC061A0C; Mon, 18 May 2020 04:33:55 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id b8so4660313pgi.11; Mon, 18 May 2020 04:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eJccfybN0sdNJ8ylX53cDwC7dY9jWBu+I0/w3Xw+cBs=; b=dhzh1omwrLM8jvSd0mWoUvTHmS4XEDbVWxMoTMADnXAKl3vN8Vx+B1sr4yx8mpwhN8 ERGpklHuqHhD7nk+hCZ6OD5cAEt1Q4kw+ePgxqT9Aa+eZT+Pf92cktTooIV4J4zrYVzK GEwdlt9w1w6jQPJA2UB83YNy2B8J+lyYRfBcsXWSvI+VoyEzgjnp2/tNXESdBC2s0iVE nvTsnGj4U40Yqdmkxqpq6Ow5jtHIWMuPxYMTahWTbGLLh42LHaNrB7Bzm2KTMxXfvQ53 +qPfPP2unWxuvvdjHxPdJU9VWELTuPyXY1LUwCAdDFYvJ+9Of06RfW7ltfDlwpc9rGVi 5NjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eJccfybN0sdNJ8ylX53cDwC7dY9jWBu+I0/w3Xw+cBs=; b=jw5Gvc2dWAVM3kOXjqy6sPebmb2jpeiePPVgF3usdTvDlEIs4FGDckA4z3Hm6yPNwR byf0p1FaNDcJw/1A+Z2zok2xZbw6DiHB7OsEkBwT1+efz5SAIINtZqek1r0WW2GojWrC 2z2/3JdEKgdLiyDNpvuGETVXIrhMN98gnJw7yZpzW78a3t2W4D39FyYGJXP2Vht8YP6x BSuxFN7Inuwxs/slJ2Tpc4wXxpWjdme1GG8Gq3l6XHlIcsa+HdjEPPBEirGOOEaiQDUy 25Eh+D7Br3C+efh/ZTU5wCl1RUbIdQYQar3wcy8TCzTwMu9eQGHG+7nssYbOa8fogZp9 ac5Q== X-Gm-Message-State: AOAM530lDtwHam4UZFNDtTnmncIZ+JhvnH8J5mdGBrHCUkr9Q/U7JIIO 6NHFc4qwJj8dabJ2KunUOxee4aTWF4agBUZ0n/X2kZkD5As= X-Received: by 2002:a62:5ec7:: with SMTP id s190mr15951343pfb.130.1589801634593; Mon, 18 May 2020 04:33:54 -0700 (PDT) MIME-Version: 1.0 References: <1589798090-11136-1-git-send-email-agordeev@linux.ibm.com> In-Reply-To: <1589798090-11136-1-git-send-email-agordeev@linux.ibm.com> From: Andy Shevchenko Date: Mon, 18 May 2020 14:33:43 +0300 Message-ID: Subject: Re: [PATCH RESEND] lib: fix bitmap_parse() on 64-bit big endian archs To: Alexander Gordeev Cc: Linux Kernel Mailing List , linux-s390@vger.kernel.org, Stable , Yury Norov , Andy Shevchenko , Amritha Nambiar , Arnaldo Carvalho de Melo , Chris Wilson , Kees Cook , Matthew Wilcox , Miklos Szeredi , Rasmus Villemoes , Steffen Klassert , "Tobin C . Harding" , Vineet Gupta , Will Deacon , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 18, 2020 at 1:40 PM Alexander Gordeev wrote: > > Commit 2d6261583be0 ("lib: rework bitmap_parse()") does > not take into account order of halfwords on 64-bit big > endian architectures. Thanks for report and the patch! Did it work before? Can we have a test case for that that we will see the failure? > Fixes: 2d6261583be0 ("lib: rework bitmap_parse()") > Cc: stable@vger.kernel.org > Cc: Yury Norov > Cc: Andy Shevchenko > Cc: Amritha Nambiar > Cc: Arnaldo Carvalho de Melo > Cc: Chris Wilson > Cc: Kees Cook > Cc: Matthew Wilcox > Cc: Miklos Szeredi > Cc: Rasmus Villemoes > Cc: Steffen Klassert > Cc: "Tobin C . Harding" > Cc: Vineet Gupta > Cc: Will Deacon > Cc: Willem de Bruijn > Signed-off-by: Alexander Gordeev > --- > lib/bitmap.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/lib/bitmap.c b/lib/bitmap.c > index 89260aa..a725e46 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -717,6 +717,19 @@ static const char *bitmap_get_x32_reverse(const char *start, > return end; > } > > +#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT) > +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx) > +{ > + maskp += (chunk_idx / 2); > + ((u32 *)maskp)[(chunk_idx & 1) ^ 1] = chunk; > +} > +#else > +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx) > +{ > + ((u32 *)maskp)[chunk_idx] = chunk; > +} > +#endif > + > /** > * bitmap_parse - convert an ASCII hex string into a bitmap. > * @start: pointer to buffer containing string. > @@ -738,7 +751,8 @@ int bitmap_parse(const char *start, unsigned int buflen, > { > const char *end = strnchrnul(start, buflen, '\n') - 1; > int chunks = BITS_TO_U32(nmaskbits); > - u32 *bitmap = (u32 *)maskp; > + int chunk_idx = 0; > + u32 chunk; > int unset_bit; > > while (1) { > @@ -749,9 +763,11 @@ int bitmap_parse(const char *start, unsigned int buflen, > if (!chunks--) > return -EOVERFLOW; > > - end = bitmap_get_x32_reverse(start, end, bitmap++); > + end = bitmap_get_x32_reverse(start, end, &chunk); > if (IS_ERR(end)) > return PTR_ERR(end); > + > + save_x32_chunk(maskp, chunk, chunk_idx++); > } > > unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32; > -- > 1.8.3.1 > -- With Best Regards, Andy Shevchenko