Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp174816lqh; Wed, 27 Mar 2024 20:09:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5eJjwRsYIFVJi9Y/rRP2flHrR2kqrxBzPMznwapr1j4BjDUfNQcUWJKzxEUDvrxPP8IudJi7wgCMOQy/rEodWsD2WDEjoDC1YmIPKPw== X-Google-Smtp-Source: AGHT+IFxiWYFzS3OKqyixcm+xiwsa2bDpibL3vjBnZP37U5NE0nhQHTb7LIFdmW7UEiLyqfjS23x X-Received: by 2002:a50:9344:0:b0:56c:195d:b168 with SMTP id n4-20020a509344000000b0056c195db168mr1120729eda.26.1711595355957; Wed, 27 Mar 2024 20:09:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711595355; cv=pass; d=google.com; s=arc-20160816; b=s61uAhpT7k9+3fn2/DmzaJszdz3bq1JaFD+db9KYc3gBP+2MExpjoSR3A828HetlJi jrk4lSyWD4jgV7q5C7K0L3HQOjHU0fhLNsXrXLsaUimcc2DCTuHd9zukSu8y+GQhKu4Q QGzgXPDAujBvqI0hVXFk1KwSF2/+l8EXMBw3Gov2164F4RuliLNaNuK06t4Hf/9OswRx owUpAX9/Dv1fvLQw88gBKfEUiMLymxRvpjkCKT9mYY8fopcc/0wpcAW+CK+SRh7RUJJi YY8g4NJ8t1psuWDdjry5clwvLWtA9MJuB6iXuvH/T4auQnwAWUyl7ZU25bmHZi93Vo4p 094A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=9WxQFMKA04hpL1oV7PFD8R5ACgMSUhqd8kYoZIZPydA=; fh=yn9wV9wxslOj8ZsJPQOXtrDm1rpy7wf2w6rIwGJm7P4=; b=SZ8680qHs486HcYV8EM4Ny9IYWGh26m+3hWu6LPZ/19sKOz4+dBjsPj6uvFg4L4oML 0lOXmzaZNt6iAx2oTzxGXaboWI/ABMn9SwV+LOCLXa8MNRiHmh/aDzH+1GKQC8Est8aN XujJYlBeFnHZyHqFCgwH4Gu9/p3c/ENeHe4mBNVkNCyv7hgWqrThe6Ln64h8ydZZmSqf q4WKvgRAwBbZjyC8jEhguiKw9sax6zYye1wupdDCtCC82YHJVA0MZDcSVSQ9UNiAitI6 +RYhP44Mp5KGsRPHYlP39QPIUbXUp6xYZgoPddar8qPQFqDSeXq4Z2ShZwGBZsaglOcg /6Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iblpSu+M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-122368-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122368-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z61-20020a509e43000000b0056c069bf61asi274728ede.7.2024.03.27.20.09.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 20:09:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122368-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iblpSu+M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-122368-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122368-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AD30B1F2C225 for ; Thu, 28 Mar 2024 03:09:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E451A32189; Thu, 28 Mar 2024 03:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iblpSu+M" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14C962D622; Thu, 28 Mar 2024 03:09:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711595341; cv=none; b=Ed7hGeEeQTlfAotWhifcUVcjIpkY/GbPC0ykJqc4AtCRs+o1aXM6nEEwO3XThr1OuibX5ZIftxsxNDnizLBcuzYvN2MqOmukWcHsXlxWKdkuoVDPqbqCSxZ7Bp/58kl5x1pIsvMOAkaCTrD3OrI4VDtBnk3vSoO5OmAfTbHhm2A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711595341; c=relaxed/simple; bh=nABLxb6h1Qjjq0SWW/DOT1BK8XdLbDeksfd3ZdK0Bpo=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=QtmXbvfhlsx49chnMeShwxVxM6Fv3gzNUi8YTE8eVrhb9EwKedx2ILLMiFL8CEVFVQcXytpGpX8F0yYiInL9dlGHZI08NOp0ZOPQpH3RJ+CfG9Cqk6e3sJVHMx8/PeAhi8jzE/cFORVW0ndbkwb8uH+KtbDzW1I0bjCOZrzGJqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iblpSu+M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 476F3C433C7; Thu, 28 Mar 2024 03:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711595340; bh=nABLxb6h1Qjjq0SWW/DOT1BK8XdLbDeksfd3ZdK0Bpo=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=iblpSu+Mhd6FpFhdEE0gklvAqe79T5CeTdZl4hBK3S0p9BUHUGVo93nECPqIfUYoS o8c/Lm9DL6bBAV7+jcjwNMDqtrWFOm+wasiEuESIwPZTdkrLpDaN/eDJo9uoY0enVV xdbxDP3WU9CFZSY9T8EJVT+OjtIk3OPb1wCzccdg/7IFs4xRQCAL6RNdL+6j8oG/Om EVldwU6Uvho0emU2TwfAkyY2Q8sIWfxvDgsWhG0VcHMdbECJppoIctldl4NKnq5062 TzOkfgABNro+CmKZT03kEqlR0qrGMAbVgFaZwY8glJmF2bQjFT3UsE2dCww32oCkyK ZHd5cihxwe4Hg== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 28 Mar 2024 05:08:56 +0200 Message-Id: Cc: , , "Roberto Sassu" , , "Ken Goldman" Subject: Re: [PATCH] ima: define an init_module critical data record From: "Jarkko Sakkinen" To: "Mimi Zohar" , "Luis Chamberlain" X-Mailer: aerc 0.17.0 References: <20240327150019.81477-1-zohar@linux.ibm.com> <80b2e479bc0c520423885a16dd46e0201a1c9418.camel@linux.ibm.com> In-Reply-To: <80b2e479bc0c520423885a16dd46e0201a1c9418.camel@linux.ibm.com> On Wed Mar 27, 2024 at 11:37 PM EET, Mimi Zohar wrote: > On Wed, 2024-03-27 at 18:54 +0200, Jarkko Sakkinen wrote: > > On Wed Mar 27, 2024 at 5:00 PM EET, Mimi Zohar wrote: > > > The init_module syscall loads an ELF image into kernel space without > > > measuring the buffer containing the ELF image. To close this kernel > > > module integrity gap, define a new critical-data record which include= s > > > the hash of the ELF image. > > >=20 > > > Instead of including the buffer data in the IMA measurement list, > > > include the hash of the buffer data to avoid large IMA measurement > > > list records. The buffer data hash would be the same value as the > > > finit_module syscall file hash. > > >=20 > > > To enable measuring the init_module buffer and other critical data fr= om > > > boot, define "ima_policy=3Dcritical_data" on the boot command line. = Since > > > builtin policies are not persistent, a custom IMA policy must include > > > the rule as well: measure func=3DCRITICAL_DATA label=3Dmodules > > >=20 > > > To verify the template data hash value, first convert the buffer data > > > hash to binary: > > > grep "init_module" \ > > > /sys/kernel/security/integrity/ima/ascii_runtime_measurements | \ > > > tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum > > >=20 > > > Reported-by: Ken Goldman > > > Signed-off-by: Mimi Zohar > > > --- > > > security/integrity/ima/ima_main.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > >=20 > > > diff --git a/security/integrity/ima/ima_main.c > > > b/security/integrity/ima/ima_main.c > > > index c84e8c55333d..4b4348d681a6 100644 > > > --- a/security/integrity/ima/ima_main.c > > > +++ b/security/integrity/ima/ima_main.c > > > @@ -902,6 +902,13 @@ static int ima_post_load_data(char *buf, loff_t = size, > > > return 0; > > > } > > > =20 > > > + /* > > > + * Measure the init_module syscall buffer containing the ELF image. > > > + */ > > > + if (load_id =3D=3D LOADING_MODULE) > > > + ima_measure_critical_data("modules", "init_module", > > > + buf, size, true, NULL, 0); > >=20 > > No reason not to ack but could be just as well (passing checkpatch): > > Please review the tag usage as defined in=20 > https://docs.kernel.org/process/submitting-patches.html. > > >=20 > > if (load_id =3D=3D LOADING_MODULE) > > ima_measure_critical_data("modules", "init_module", buf, size, > > true, NULL, 0); > >=20 > > < 100 characters > > From what I understand, it's still preferable to stay under the 80 charac= ter > limit, but checkpatch.pl will not complain. From=20 > https://www.kernel.org/doc/Documentation/process/maintainer-tip.rst: > > "The 80 character rule is not a strict rule, so please use common sense w= hen > breaking lines. Especially format strings should never be broken up." I agree with that is your decision to make (as maintainer of IMA)! BTW, I guess process/coding-style.rst would be better ref here because maintainer-tip.rst is meant only for arch/x86 tree (aka tip.git). That said, both maintainer-tip.rst and coding-style.rst recommend the same 80 character length. I have no idea whether 80 or 100 character should be considered as "recommended". The formatted string example is somewhat weird too because you should not break that even if it was 150 characters so it does not have any relation to 100 character limit... R, Jarkko