Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4167689pxu; Mon, 12 Oct 2020 11:10:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4iMyounQ6VtYG6UMJRARMqLONpoYMG5Xk8lueyDCGaYYySoIHG1ojQ5UVYnJp7QOkG3Ou X-Received: by 2002:a17:906:cb82:: with SMTP id mf2mr28774988ejb.435.1602526200630; Mon, 12 Oct 2020 11:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602526200; cv=none; d=google.com; s=arc-20160816; b=rOzOsJ3ANm7wjKXtgYEj8kAzo+Xaw5jMqcSJuZigTK9cUAZWLO4ZfY4V+dASXFg9Ap NeL1A4GTEiAZLDrVPm1pICNofOnzKfG7G8PeO62wYinFeKt/6Nyj7zoXM7qF8Lm0e5iQ 7KYcjJboHPNeKL7D4IBYlUN5vl4NvhyRtZWalZ7eTOyjDJ13SMqkQkK1+3q5cUCQH50l XMWRpJdileXw7vT/0lFmmUx646xkUuRI442sAZh6YJFzyktBE5Vx7gHczOVM+87VMH9H RhYZhLJy/HWdmykZxXFtH07stFVB+Sx6NgjFQlWWmKiEL5NBplW0rqvoq8ncTdf3KQWL wLbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=/7nU27nEPE9GsChTBrHin4CFgRRnfALGVRA0k8kGvvw=; b=XB2aqWCQDBPTYTwd86Hl2nkOgeYg2fmMNYC8leapZv/p5wO807fLL97swP//Ol7Ohl 6CWb1Qrqn1DZJGStiwspbWvnyxu2jAzmAllOeA4+wktmmkKoImEp5faiM8ORFsEJ0v/P XpyRL7Cvf42gC/jVtkm9T1DnBkqp4SkQurni2+fuM/KhFlF8GRC03Nx66N3+6MRIu+rp j3lwZI+2fLgjI1Ez4kcgrzmK2KEv7tSCNtnEvqXc2Qu8SKBlq56WggykIvvlnLdz1xR3 bgRQc05S36TNs0v/asL5QHtwQaZdm/p4pC5wqKkzzFUeYT/AfIsQzBV9dZ97T4T3hZ0s Bfzg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz2si12691927ejc.47.2020.10.12.11.09.37; Mon, 12 Oct 2020 11:10:00 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404176AbgJLSGI (ORCPT + 99 others); Mon, 12 Oct 2020 14:06:08 -0400 Received: from smtprelay0239.hostedemail.com ([216.40.44.239]:48904 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403943AbgJLSGI (ORCPT ); Mon, 12 Oct 2020 14:06:08 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 5256018029129; Mon, 12 Oct 2020 18:06:07 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2110:2393:2559:2562:2693:2828:2894:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:4321:5007:8603:10004:10400:10848:11026:11232:11658:11914:12043:12048:12296:12297:12438:12679:12740:12760:12895:13069:13311:13357:13439:14096:14097:14659:14721:21080:21212:21611:21627:21990:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: comb67_5601f4e271fc X-Filterd-Recvd-Size: 2685 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf19.hostedemail.com (Postfix) with ESMTPA; Mon, 12 Oct 2020 18:06:05 +0000 (UTC) Message-ID: Subject: Re: [PATCH] ima: Fix sizeof mismatches From: Joe Perches To: Mimi Zohar , Colin King , 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 Date: Mon, 12 Oct 2020 11:06:04 -0700 In-Reply-To: References: <20201007110243.19033-1-colin.king@canonical.com> <55ae0b6152c84013d483b1bbecb28a425801c408.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. cheers, Joe