From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 729D6C43457 for ; Mon, 19 Oct 2020 22:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E21122200 for ; Mon, 19 Oct 2020 22:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Pppi9Jz2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388794AbgJSW7j (ORCPT ); Mon, 19 Oct 2020 18:59:39 -0400 Received: from linux.microsoft.com ([13.77.154.182]:34820 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388772AbgJSW7e (ORCPT ); Mon, 19 Oct 2020 18:59:34 -0400 Received: from [192.168.0.104] (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id A9C2820B36E7; Mon, 19 Oct 2020 15:59:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A9C2820B36E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1603148373; bh=v6MzvmSWcZVS4ikkTcvRXsjiTMX3satCUGMxxfinNYA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Pppi9Jz2ZYnofJUpwD3486W2l8oLpVmR+iMCCbJ5soOvkcbVAn+xJoGAV3IL6cjgg Cpb8MG2fVhfsy6uxkTmq5BhfGxJz/cZVogTwu+0cjEfOE4AJQjkHbjU4zgFb6C/SCB LAyeeQeEfV4lBRq7XDVWYXRV3BYE+LvWOslYy9gc= Subject: Re: [PATCH] file2bin: Pass the right values to size and count parameters for fread() To: Mimi Zohar , pvorel@suse.cz Cc: linux-integrity@vger.kernel.org References: <20201019200526.12678-1-nramas@linux.microsoft.com> <9dd83103f724484a8f1febb37b54616d136930fe.camel@linux.ibm.com> From: Lakshmi Ramasubramanian Message-ID: Date: Mon, 19 Oct 2020 15:59:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org On 10/19/20 3:30 PM, Mimi Zohar wrote: > On Mon, 2020-10-19 at 15:22 -0700, Lakshmi Ramasubramanian wrote: >> On 10/19/20 3:12 PM, Mimi Zohar wrote: >>> Hi Lakshmi, >>> >>> On Mon, 2020-10-19 at 13:05 -0700, Lakshmi Ramasubramanian wrote: >>>> The 2nd parameter to fread() namely "size" specifies the size, in >>>> bytes of each element to be read, and the 3rd parameter namely "count" >>>> specifies the number of elements, each one with a size of "size" bytes. >>>> >>>> size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); >>>> >>>> But in the function file2bin() the values passed to "size" and "count" >>>> are reversed causing the function to return an error eventhough the file >>>> was sucdessfully read. >>>> >>>> Pass the right values to "size" and "count" parameters for fread() in >>>> the function file2bin(). >>>> >>>> Signed-off-by: Lakshmi Ramasubramanian >>>> --- >>>> src/evmctl.c | 3 ++- >>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/src/evmctl.c b/src/evmctl.c >>>> index 7ad1150..d49988e 100644 >>>> --- a/src/evmctl.c >>>> +++ b/src/evmctl.c >>>> @@ -221,7 +221,8 @@ static unsigned char *file2bin(const char *file, const char *ext, int *size) >>>> fclose(fp); >>>> return NULL; >>>> } >>>> - if (fread(data, len, 1, fp) != len) { >>>> + >>>> + if (fread(data, 1, len, fp) != len) { >>>> log_err("Failed to fread %zu bytes: %s\n", len, name); >>>> fclose(fp); >>>> free(data); >>> >>> Wasn't this problem addressed by Vitaly's patch. Please look at commit >>> c89e8508864b ("ima-evm-utils: Fix reading of sigfile"). >>> >> >> You are right Mimi. I missed the patch posted by Vitaly. Sorry for the >> duplicate one. >> >> Looks like Vitaly's change hasn't been merged to "master" branch yet in >> https://github.com/pevik/ima-evm-utils > > Only after the release would it be in master. Until then it would be > in next, which it isn't either. Can I add your Reviewed-by tag on > this patched? Sure. Reviewed-by: Lakshmi Ramasubramanian -lakshmi