From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Date: Mon, 12 Oct 2020 18:06:04 +0000 Subject: Re: [PATCH] ima: Fix sizeof mismatches Message-Id: List-Id: References: <20201007110243.19033-1-colin.king@canonical.com> <55ae0b6152c84013d483b1bbecb28a425801c408.camel@perches.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 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