Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp629480pxu; Wed, 7 Oct 2020 11:32:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDVBoU/6fIcrYLbcpr2EmFrQULRzOADLWVjGIE6UlNHB/IwT/VyzVfvrSq1kuvVM+WFdBP X-Received: by 2002:a17:906:eb59:: with SMTP id mc25mr4650848ejb.34.1602095567989; Wed, 07 Oct 2020 11:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602095567; cv=none; d=google.com; s=arc-20160816; b=azvs63iPOD/eh16sLvPKXcLWfLVhxUKs3FKIKxLSpmLcxw2YiuDRtxnt17eowlQx/v zBK2ufjVj61WMHUN5tFxjCSUZfd7U55C+S0e17QBvuRVLETyYuuDhwxuNm8/mWeoOpgk 2IrqvjiIv5jjBuYaib2g2mtcV0A0kFkakEYbVH0j3/IBtivZm/AAWwoRhbhK+AQQmtOi pJlJ00u2EML9nX89YOscGunEkHksgVtqJCAGBZfpEOtnQA8OXgxFxHcBFuFK5q08AM7+ TuNp/j3FERGhL5g8kDzasAHfJ9t++3Brph+i21hCwfHfoEWb5EFXUiA6yoRTTNKd2ptS QePw== 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=1vYPwbeItfhizXoOpqpBb/PR/2ysg+uGB3pavsutObg=; b=yAejrKA7u6aeOesDt98x4AgYn+fpchdF6Z4iyoY6lCyjjpo7kZpQPlNxfWVV4eAjdt 67dzXmn5sEmVIng4ISAvvkJFRYmFFGeAtrNBhEe3uRGQteq7MB4SclL6cPGPKtXUPoVz idAiL3Btrs1icS2ON7N/EtjUUt+Eb/KZqW60cKzWFJgaVvZhKkarPffEGVT0hghaN0pj lLxaE47X8TFS7u7QkpJk9uxXb4eqFER2B5kblO9K20ktd3GUDc7D3K6Vh4SannZUCaZE ZogTdIkelFv0HceEGFuI39+lPj4bNZhYGkxx3FTjsh8h75EMo50Wspv7SoWVArTLsqym 2rYw== 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 e8si1949655edn.283.2020.10.07.11.32.24; Wed, 07 Oct 2020 11:32:47 -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 S1727033AbgJGS1J (ORCPT + 99 others); Wed, 7 Oct 2020 14:27:09 -0400 Received: from smtprelay0145.hostedemail.com ([216.40.44.145]:36068 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726152AbgJGS1J (ORCPT ); Wed, 7 Oct 2020 14:27:09 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id D3A08100E7B49; Wed, 7 Oct 2020 18:27: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:1540:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:2894:3138:3139:3140:3141:3142:3352:3622:3865:3866:3868:3870:3871:3872:4321:5007:8603:10004:10400:10848:11026:11232:11658:11914:12043:12048:12296:12297:12438:12740:12760:12895:13069:13311:13357:13439: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: point10_6007cd0271d1 X-Filterd-Recvd-Size: 1995 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA; Wed, 7 Oct 2020 18:27:06 +0000 (UTC) Message-ID: <55ae0b6152c84013d483b1bbecb28a425801c408.camel@perches.com> Subject: Re: [PATCH] ima: Fix sizeof mismatches From: Joe Perches To: Colin King , 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 Date: Wed, 07 Oct 2020 11:27:04 -0700 In-Reply-To: <20201007110243.19033-1-colin.king@canonical.com> References: <20201007110243.19033-1-colin.king@canonical.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 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...