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=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 21389C43467 for ; Mon, 12 Oct 2020 18:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E653220776 for ; Mon, 12 Oct 2020 18:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404140AbgJLSK0 (ORCPT ); Mon, 12 Oct 2020 14:10:26 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:56599 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbgJLSKY (ORCPT ); Mon, 12 Oct 2020 14:10:24 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kS2H6-00089W-55; Mon, 12 Oct 2020 18:10:20 +0000 Subject: Re: [PATCH] ima: Fix sizeof mismatches To: Joe Perches , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E . Hallyn" , Roberto Sassu , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20201007110243.19033-1-colin.king@canonical.com> <55ae0b6152c84013d483b1bbecb28a425801c408.camel@perches.com> From: Colin Ian King Message-ID: <0ceb198a-a313-f542-49cc-c0b9f6b1ea52@canonical.com> Date: Mon, 12 Oct 2020 19:10:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/10/2020 19:06, Joe Perches wrote: > On Mon, 2020-10-12 at 13:51 -0400, Mimi Zohar wrote: >> On Wed, 2020-10-07 at 11:27 -0700, Joe Perches wrote: >>> On Wed, 2020-10-07 at 12:02 +0100, Colin King wrote: >>>> An incorrect sizeof is being used, sizeof(*fields) is not correct, >>>> it should be sizeof(**fields). This is not causing a problem since >>>> the size of these is the same. Fix this in the kmalloc_array and >>>> memcpy calls. >>> [] >>>> diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c >>> [] >>>> @@ -216,11 +216,11 @@ int template_desc_init_fields(const char *template_fmt, >>>> } >>>> >>>> if (fields && num_fields) { >>>> - *fields = kmalloc_array(i, sizeof(*fields), GFP_KERNEL); >>>> + *fields = kmalloc_array(i, sizeof(**fields), GFP_KERNEL); >>>> if (*fields == NULL) >>>> return -ENOMEM; >>>> >>>> - memcpy(*fields, found_fields, i * sizeof(*fields)); >>>> + memcpy(*fields, found_fields, i * sizeof(**fields)); >>> >>> Maybe use kmemdup instead. >>> >>> if (fields && num_fields) { >>> *fields = kmemdup(found_fields, i * sizeof(**fields), GFP_KERNEL); >>> etc... >>> >> >> Thanks, Joe. Since this patch will be backported, perhaps it would be >> better to leave this as a bug fix and upstream other changes >> independently. > > IMO: > > This patch doesn't need need backporting as it doesn't > actually fix anything other than a style defect. > > void * and void ** are the same size. indeed, same size, it's a semantic difference *and* a style fix :-) Colin > > cheers, Joe >