Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2612051ybk; Mon, 18 May 2020 03:38:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuCChNapU9mknofbGN7CDN2jgoVARQzWUHv7Vg99a0RppKDTRcDOeezz5oz5Uwthw8IhBw X-Received: by 2002:a50:d6d0:: with SMTP id l16mr13459807edj.317.1589798311300; Mon, 18 May 2020 03:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589798311; cv=none; d=google.com; s=arc-20160816; b=qvX2sVZmlQ7Fxr/WLj11aEuWw6bQT+783Q2H41rt1hTjMvhT4cQzm9+OyOL3/vZl8x zJoijR+HAMynMoSqor7mOrJRL6KhIQE15xfDNqnjbFaF8VDOqEdX8IwKCe6tn8tUW1/8 A8/wwFBuGdJ+ZN0R46vZ7HsEEZdeTCAS8pUix+w0ymUYE5eSTaF1NKLynmEt7Gi/Km6Y uOtgDo5dQSWH3TpdF6/YCQ87J7vBur0NuAL40cbbneLykmNXTlqUwqKHjcT1e1UugyR/ oBi/92OFotEkvOsIO4Rk2XqDqQYeD/3zz9eLaSwfQBz1PVOmunrQB6fFi1fg8RMvk+n3 1oZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=/xX6lb4+W6KNKIyD3xpUOIY8DdW7hMduMKCP4q/7QPI=; b=WZBnN5zG/DcH7kSpWwnEPtsYICPAv120YSP9Fia+m5ZQx9/YBJCekIzoH6tyj26Dl/ iVoi121sLrfnDdKdXfKCdtoARUzMuS3INIMrmeBVb1qG93vWJwPShT3uZb0i+8LdkWjp plTAopx5kgWVEXjH1I6IQGgJMVXNWiA76byLAARitgulsUPK8K2ThbuOsFXqej0h3KXv KyFZlYCAsMdlrV9QjcpNNLz3vMc9LM5Or0t5Yrv30w3KrWKx4t36CP7USC7EiT1+hrNq j8K/K8MFes3NzsbhA/7CqNMaiJ88wvSNFq2/qHUO3Fp5xMpKJnv0h2QRNkEU8Rab63PS j1Cw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h2si6249729ejc.510.2020.05.18.03.38.07; Mon, 18 May 2020 03:38:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbgERKgG (ORCPT + 99 others); Mon, 18 May 2020 06:36:06 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:25472 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726283AbgERKgE (ORCPT ); Mon, 18 May 2020 06:36:04 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04IAXKG7178322; Mon, 18 May 2020 06:35:10 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 312cagnj07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 May 2020 06:35:10 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04IAXPUH178863; Mon, 18 May 2020 06:35:09 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 312cagnhy3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 May 2020 06:35:09 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04IAVTwY009196; Mon, 18 May 2020 10:35:07 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma05fra.de.ibm.com with ESMTP id 3127t5hk4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 May 2020 10:35:06 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04IAXqJe59376112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 May 2020 10:33:52 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C10611C054; Mon, 18 May 2020 10:35:04 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 93D0711C04C; Mon, 18 May 2020 10:35:03 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.23.117]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 18 May 2020 10:35:03 +0000 (GMT) From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: linux-s390@vger.kernel.org, Alexander Gordeev , stable@vger.kernel.org, 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 Subject: [PATCH RESEND] lib: fix bitmap_parse() on 64-bit big endian archs Date: Mon, 18 May 2020 12:34:50 +0200 Message-Id: <1589798090-11136-1-git-send-email-agordeev@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-18_04:2020-05-15,2020-05-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=1 bulkscore=0 mlxlogscore=999 adultscore=0 clxscore=1011 impostorscore=0 lowpriorityscore=0 cotscore=-2147483648 phishscore=0 malwarescore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005180095 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 2d6261583be0 ("lib: rework bitmap_parse()") does not take into account order of halfwords on 64-bit big endian architectures. 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