Received: by 10.223.164.202 with SMTP id h10csp400906wrb; Thu, 9 Nov 2017 08:04:52 -0800 (PST) X-Google-Smtp-Source: ABhQp+SGT/5tcQRgxF/JLyoaCGSZW0OvQtinQU1cdh/K09GMAD4VWF+/ya8zVDccx/mBtufpn7su X-Received: by 10.99.45.65 with SMTP id t62mr922155pgt.446.1510243492402; Thu, 09 Nov 2017 08:04:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510243492; cv=none; d=google.com; s=arc-20160816; b=oSu08I0hVQGNWpJA3Z8IRewpQjj4qlYDiBxJ/1jgp4R+wDWjZZiO77eU7ZQHuFIn6d gIryT/g5U7J+GaHoomGmnC2EfnPzR/I1zgjvHQe9GO8UrAORu8TuGonWTVAy/sbnc7oy ZC2Q3sWdg9oKU4eG7bmnOdQxSOzyfBwvcIcmj/qeP6K/RtcNTsn4ADuht53P21hhSmon zC33gvSQqTy6AUGuaaeVfoszC5tb4tA8OyjhhLOgdqb2MG5OCISKryxphUuTk8wphxpC FCu2IxptqCH3JNn3Pz/xZS3UScK+0+scw6Yd2/92Hcuak2UoY+gwHznigtNpsFx85smB UZfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :content-transfer-encoding:date:message-id:in-reply-to:cc:to:from :reply-to:subject:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=wgmELavuVJs1Se1XzHtakSl4yiuGLIBKtR1Vbqm1p4g=; b=IL26i6hhY6YUbJtGVS+KhwwsO4eKv9wsBBJYUL0mOSYklD25m8ZigKw7gM2U+oIMgk FTZFecCoFVyv8ZLCJFGldMvA+SXVLiDIcxWl4LWBlpaqBHKLkYKo5IAM7utbEMZHCTO9 7XO5IOqfO7ibWfCvJX4kcRqvwRZ8vWbmWMSX0SN/qZXqLYOdQf9gNoVixR7NSrS2Qpha 3VZZbf1A9sAmzSxaR7z/e5f1LIe2cPYpf2+1XesdHvkbm0/33N8cmYTVwiihGaamdYy4 sSQLyo2E80zocDgosb0qvVn2WTfH/Lmc34t+j2fecCD+HQCxazo4RoE5B8acw2T2zYcN RVbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=LWQOARPI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a14si2982326pgv.479.2017.11.09.08.04.41; Thu, 09 Nov 2017 08:04:52 -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=pass header.i=@samsung.com header.s=mail20170921 header.b=LWQOARPI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753111AbdKIQDf (ORCPT + 81 others); Thu, 9 Nov 2017 11:03:35 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:61657 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752182AbdKIQDe (ORCPT ); Thu, 9 Nov 2017 11:03:34 -0500 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20171109160332epoutp0188156839c6a83511e418e415696317f9~1dmHGiMyr0128501285epoutp01p for ; Thu, 9 Nov 2017 16:03:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20171109160332epoutp0188156839c6a83511e418e415696317f9~1dmHGiMyr0128501285epoutp01p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1510243412; bh=wgmELavuVJs1Se1XzHtakSl4yiuGLIBKtR1Vbqm1p4g=; h=Subject:Reply-To:From:To:CC:In-Reply-To:Date:References:From; b=LWQOARPIgchyP0KblAruKFQz/FO0eHdMQEUD/97W+/RK52VKqQaUgFfkGFYxbjyLZ gFSQCM7jsLuH4kExbrKy8JAH0HZn53bAQXTp1LAJTcebyLcvlOGRienxphp/72HcqR iqO8zTULAZss4dDqIFvkvK4+djVp5QcgCjg0kovc= Received: from epsmges5p2new.samsung.com (unknown [182.195.40.74]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20171109160331epcas5p485d907bb2cf5b70d416ab8031f290198~1dmGjQHsA1929619296epcas5p4n; Thu, 9 Nov 2017 16:03:31 +0000 (GMT) X-AuditID: b6c32a4a-161ff70000001145-0e-5a047c53a030 Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id AB.53.04421.35C740A5; Fri, 10 Nov 2017 01:03:31 +0900 (KST) Mime-Version: 1.0 Subject: RE: Re: [PATCH 1/1] mpi: check for shift exponent greater than 31. Reply-To: v.narang@samsung.com From: Vaneet Narang To: Ayush Mittal CC: "dhowells@redhat.com" , "aryabinin@virtuozzo.com" , "james.l.morris@oracle.com" , "linux-kernel@vger.kernel.org" , AMIT SAHRAWAT , PANKAJ MISHRA X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: <9150.1509545421@warthog.procyon.org.uk> X-Drm-Type: Y,confirm X-EPLocale: en_US.EUC-KR X-EPWebmail-Msg-Type: personal X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20171109145541epcms5p639da345b9cfdf020d35b10f962617cd6@epcms5p6> Date: Thu, 09 Nov 2017 14:55:41 +0000 X-CMS-MailID: 20171109145541epcms5p639da345b9cfdf020d35b10f962617cd6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE X-MTR: 20171109145541epcms5p639da345b9cfdf020d35b10f962617cd6 CMS-TYPE: 105P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAJsWRmVeSWpSXmKPExsWy7bCmpm5wDUuUwdUTGhYXd6dafJn0jt3i yu/97Bbvmn6zWPQ9DrK4vGsOm8W9N1uZHNg9Pj69xeLxft9VNo++LasYPT5vkvN4vf8QYwBr VKpNRmpiSmqRQmpecn5KZl66rZJ3cLxzvKmZgaGuoaWFuZJCXmJuqq2Si0+ArltmDtARSgpl iTmlQKGAxOJiJX07m6L80pJUhYz84hJbpWhDQyM9QwNzPSMjIz0T01grI1OgkoTUjPeLvzIW vFas2Pt+HVsD42+FLkZODgkBE4lHb66xdDFycQgJ7GaUWHD+KGMXIwcHr4CgxN8dwiA1wgLe Ep331zKD2EICchLHb+xmhIjrSJyYtwasnE1AS+JjSzhIWERATaL/xj1mkJHMApuYJI5++s4M sYtXYkb7UxYIW1pi+/KtYHM4BUwl7l2fyQ4RF5X40wBTIyGxeuFzNghbTmLa1zXMMDXvj81n hLBFJFrvnYWKC0o8+LkbKl4rMe3xNKg5MhLfv/azghwkIdDNKHH/7VcWCGcKo8Sief+gqswl zp+cDzaJV8BX4uj5NlYQm0VAVaJjxluoDS4SG/r3MIHYzALaEssWvmYG+Z5ZQFNi/S59iBJZ iamn1jFB2LYS81vnMUOU80n0/n7CBAuIHfOeME1gVJmFCOpZSIbOQhi6gJF5FaNkakFxbnpq sWmBUV5quV5xYm5xaV66XnJ+7iZGcGrU8trBuOyczyFGAQ5GJR7eF6uYo4RYE8uKK3MPMUpw MCuJ8JrmsEQJ8aYkVlalFuXHF5XmpBYfYjQFem8is5Rocj4wbeeVxBuaWBqYmJmZGxoYWJoo ifMe21kaKSSQnliSmp2aWpBaBNPHxMEp1cBooJWdInWBO2aBhGd9euGD8H1y+z8wZxr8/ewp v/C0Vtltzmhv7Vi5ee87008f1thq/Oil3ZaDVxVtuROsWSq+7Eq9/z/Ss2oSU/7/Ay/vtten 50f8CMmNqy164ij0Qt9eS+b2OrUU56VngtgNV9ZXbTPTW303cIuB3AaJLffMu8uP8gsy9iux FGckGmoxFxUnAgCW4p7JowMAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20171024052942epcas5p48384a3861fbfa90a37a03236828b9b67 X-RootMTR: 20171024052942epcas5p48384a3861fbfa90a37a03236828b9b67 References: <9150.1509545421@warthog.procyon.org.uk> <1508822823-31231-1-git-send-email-ayush.m@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =C2=A0=0D=0AHi,=0D=0A=0D=0A>>=20This=20patch=20check=20for=20shift=20expone= nt=20greater=20than=2031,=0D=0A=0D=0AYes,=20This=20should=20be=20=22check= =20for=20shift=20exponent=20greater=20than=20BITS_PER_LONG=22=0D=0A=0D=0A>F= irstly,=20isn't=20it=2063=20on=2064-bit=20machines?=0D=0A=0D=0ADescription= =20of=20patch=20is=20specific=20to=2032bit=20machine=20but=20patch=20is=20m= ade=20considering=2064bit=20in=20mind=20also.=20=0D=0Aand=20this=20is=20the= =20precisly=20the=20reason=20we=20have=20been=20comparing=20with=20BITS_PER= _MPI_LIMB=20=0D=0Aas=20BITS_PER_MPI_LIMB=20is=20BITS_PER_LONG.=0D=0A=0D=0A>= Secondly,=20this=20is=20the=20wrong=20way=20to=20do=20things.=20=20The=20ba= nner=20comment=20on=0D=0A>mpihelp_lshift(),=20for=20example,=20says=20that= =20the=20function=20has=20the=20following=0D=0A>argument=20constraints:=0D= =0A=0D=0A>=090=20<=20CNT=20<=20BITS_PER_MP_LIMB=0D=0A=0D=0A>so=20sh1=20and= =20sh2=20must=20both=20be=20in=20the=20range=201-31=20or=201-63,=20assuming= =20cnt=20is=0D=0A>within=20its=20constraints.=0D=0A=0D=0AYou=20are=20right,= =20there=20is=20already=20a=20comment=20for=20the=20range=20but=20in=20our= =20case=20caller=20was=20mpi_powm()=20itself=0D=0Aso=20to=20fix=20UBSAN=20w= arning=20we=20prefferd=20handling=20in=20mpihelp_lshift/mpihelp_rshift.=0D= =0A=0D=0ACall=20Sequence:=0D=0A=5B0-1.1677=5D=20=5B=5D=20(ubsan_e= pilogue)=20from=20=5B=5D=20(__ubsan_handle_shift_out_of_bounds+0x= f4/0x13c)=0D=0A=5B0-1.1677=5D=20=5B=5D=20(__ubsan_handle_shift_ou= t_of_bounds)=20from=20=5B=5D=20(mpihelp_lshift+0xf0/0x160)=0D=0A= =5B0-1.1677=5D=20=5B=5D=20(mpihelp_lshift)=20from=20=5B= =5D=20(mpi_powm+0x308/0xc7c)=0D=0A=0D=0AScenario:=20MPI=20mod=20passed=20to= =20mpi_powm=20has=200=20last=20valid=20limb.=20=0D=0A=0D=0Acount_leading_ze= ros()=20returns=2032/64=20when=20last=20valid=20limb=20of=20mod=20is=200.= =0D=0A=0D=0A*=20If=20=40x=20is=200=20then=20the=20result=20is=20COUNT_LEADI= NG_ZEROS_0.=0D=0A*/=0D=0Astatic=20inline=20int=20count_leading_zeros(unsign= ed=20long=20x)=0D=0A=23define=20COUNT_LEADING_ZEROS_0=20BITS_PER_LONG=0D=0A= =0D=0Aint=20mpi_powm(MPI=20res,=20MPI=20base,=20MPI=20exp,=20MPI=20mod)=0D= =0A=7B=0D=0A....=0D=0A=20=20=20=20=20=20=20=20mod_shift_cnt=20=3D=20count_l= eading_zeros(mod->d=5Bmsize=20-=201=5D);=20=20-->=20count_leading_zeros=20c= an=20return=2032/64=0D=0A=20=20=20=20=20=20=20=20if=20(mod_shift_cnt)=0D=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20mpihelp_lshift(mp,=20mod->d= ,=20msize,=20mod_shift_cnt);=20-->=2032/64=20can=20be=20passed=20to=20mpihe= lp_lshift=0D=0A....=0D=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20/*= =20Remove=20any=20leading=20zero=20words=20from=20the=20result.=20=20*/=0D= =0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20(mod_shift_cnt)=0D= =0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= mpihelp_rshift(rp,=20rp,=20rsize,=20mod_shift_cnt);=20-->=20Similarly=2032/= 64=20can=20be=20passed=20to=20mpihelp_rshift=0D=0A....=09=09=09=09=09=09=0D= =0A=7D=09=09=09=09=09=09=0D=0A=0D=0A=0D=0A>Therefore=20if=20it=20needs=20a= =20checking,=20you=20only=20need=20to=20check=20cnt=20on=20entry=20to=20the= =0D=0A>function,=20rather=20than=20checking=20sh1=20and=20sh2=20inside=20th= e=20loop.=20=20Further,=20you=0D=0A>should=20use=20pr_err()=20so=20that=20w= e=20know=20that=20this=20has=20gone=20wrong=20and=20return=20an=0D=0A>error= =20to=20the=20caller=20(there=20are=20security=20implications).=0D=0A=0D=0A= Since=20we=20were=20not=20sure=20about=20checking=20cnt=20and=20returning= =20some=20error=20value.=20we=20thought=20it=20may=20break=20mpi_powm().=0D= =0AWe=20preferred=20doing=20a=20clean=20handling=20of=20invalid=20input=20w= ithout=20changing=20any=20behaviour=20of=20mpihelp_lshift/rshift=20.=20=0D= =0APlease=20suggest=20how=20overflow=20can=20handled=20without=20breaking= =20mpi_powm().=0D=0A=0D=0A>Further,=20have=20you=20checked=20the=20caller= =20to=20see=20if=20they=20do=20ever=20violate=20the=0D=0A>constraints?=0D= =0A=0D=0AFrom=20caller=20side,=20only=20issue=20which=20i=20can=20think=20i= s=20passing=200=20in=20as=20last=20valid=20limb=20of=20mod.=20Is=20this=20a= ny=0D=0Aconstraint=20?=0D=0A=0D=0ARegards,=0D=0AVaneet=20Narang From 1582873159320778398@xxx Wed Nov 01 14:11:18 +0000 2017 X-GM-THRID: 1582115609131952865 X-Gmail-Labels: Inbox,Category Forums