Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965033AbcKXM21 (ORCPT ); Thu, 24 Nov 2016 07:28:27 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35493 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936406AbcKXM2X (ORCPT ); Thu, 24 Nov 2016 07:28:23 -0500 MIME-Version: 1.0 In-Reply-To: <5807.1479987214@warthog.procyon.org.uk> References: <147997746306.9316.227351186233378585.stgit@warthog.procyon.org.uk> <147997747766.9316.11606802798600210253.stgit@warthog.procyon.org.uk> <5323.1479986239@warthog.procyon.org.uk> <5807.1479987214@warthog.procyon.org.uk> From: Andrey Ryabinin Date: Thu, 24 Nov 2016 15:20:08 +0300 Message-ID: Subject: Re: [PATCH 2/2] MPI: Fix mpi_powm() when exponent is 0 and the result has no limbs To: David Howells Cc: jmorris@namei.org, Dmitry Kasatkin , LKML , stable@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-ima-devel@lists.sourceforge.net Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1053 Lines: 31 2016-11-24 14:33 GMT+03:00 David Howells : > Andrey Ryabinin wrote: > >> > David Howells wrote: >> > >> >> + if (!rp) { >> >> + if (mpi_resize(res, 1) < 0) >> > >> > This is better done with RESIZE_IF_NEEDED(). >> > >> >> mpi_resize() is equal to RESIZE_IF_NEEDED(), it also checks for allocated space: >> >> int mpi_resize(MPI a, unsigned nlimbs) >> { >> .... >> if (nlimbs <= a->alloced) >> return 0; /* no need to do it */ > > Hmmm... In that case, should your patch use mpi_resize() rather than > RESIZE_IF_NEEDED()? It's a trivial case that we should perhaps weed out much > earlier (ie. reject the key if exp<2 or mod<2), but it would make the object > file slightly smaller not to do the test twice. > Right, it could be mpi_resize(). I realized that these two functions do the exactly the same thing only after I send the patch. We could even remove RESIZE_IF_NEEDED() to not confuse people, because currently it has no users. > David