From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) (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 1D3812E630; Fri, 9 Feb 2024 12:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707480211; cv=none; b=CXrAZ42b1z5HqaoB0Sn778zf1t4xyZH0kN+ddfOQDYZrizn9Ba5xTCs9G0FIy3lXwGHKF0pGAnB2dRarUL8M2CUJyjwdcYwWseTJW0MWA0JrgNXMAVuRo+8Gmgwuu5w8yIgfi0EuM3lay/YwVkCTV5rYQEeDtWamWrM6y/ZuiaM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707480211; c=relaxed/simple; bh=BhA/UikenM4m0IyfeHs3E+dkP69p7UWIJfw5VFHgk24=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=brJx/cQC5LWOZnAB7EiCvcPfLjwyigMZaHefHf1hZyqHCwZh4ThybmE52nP5ARE0e50TmXZEEBD+TO+mV2w5BbAQASuTVnKtgyjHUnzHnKZ7S7wckaYJgH0+F0KRz43oVDuKke+K6FfAHDqNY1l7ILNKjUEDXUfvd4JtboShyn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4TWXDB6LM8z9xvhR; Fri, 9 Feb 2024 19:48:10 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id DB61B14086B; Fri, 9 Feb 2024 20:03:09 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwAXBChtFMZlv1EoAg--.21619S2; Fri, 09 Feb 2024 13:03:09 +0100 (CET) Message-ID: Subject: Re: [PATCH v9 12/25] security: Introduce file_post_open hook From: Roberto Sassu To: Christian Brauner Cc: viro@zeniv.linux.org.uk, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, shuah@kernel.org, mic@digikod.net, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Roberto Sassu , Stefan Berger Date: Fri, 09 Feb 2024 13:02:49 +0100 In-Reply-To: <20240209-giert-erlenholz-b131fa85ee36@brauner> References: <20240115181809.885385-1-roberto.sassu@huaweicloud.com> <20240115181809.885385-13-roberto.sassu@huaweicloud.com> <20240209-luftleer-jobangebote-6d6ab29b7191@brauner> <86ab971f45c2ff11dcbdeab78b4b050f07495f55.camel@huaweicloud.com> <20240209-giert-erlenholz-b131fa85ee36@brauner> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.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c4S7UUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAIBF1jj5Y3PwAAsh On Fri, 2024-02-09 at 12:34 +0100, Christian Brauner wrote: > On Fri, Feb 09, 2024 at 11:46:16AM +0100, Roberto Sassu wrote: > > On Fri, 2024-02-09 at 11:12 +0100, Christian Brauner wrote: > > > On Mon, Jan 15, 2024 at 07:17:56PM +0100, Roberto Sassu wrote: > > > > From: Roberto Sassu > > > >=20 > > > > In preparation to move IMA and EVM to the LSM infrastructure, intro= duce the > > > > file_post_open hook. Also, export security_file_post_open() for NFS= . > > > >=20 > > > > Based on policy, IMA calculates the digest of the file content and > > > > extends the TPM with the digest, verifies the file's integrity base= d on > > > > the digest, and/or includes the file digest in the audit log. > > > >=20 > > > > LSMs could similarly take action depending on the file content and = the > > > > access mask requested with open(). > > > >=20 > > > > The new hook returns a value and can cause the open to be aborted. > > > >=20 > > > > Signed-off-by: Roberto Sassu > > > > Reviewed-by: Stefan Berger > > > > Acked-by: Casey Schaufler > > > > Reviewed-by: Mimi Zohar > > > > --- > > > > fs/namei.c | 2 ++ > > > > fs/nfsd/vfs.c | 6 ++++++ > > > > include/linux/lsm_hook_defs.h | 1 + > > > > include/linux/security.h | 6 ++++++ > > > > security/security.c | 17 +++++++++++++++++ > > > > 5 files changed, 32 insertions(+) > > > >=20 > > > > diff --git a/fs/namei.c b/fs/namei.c > > > > index 71c13b2990b4..fb93d3e13df6 100644 > > > > --- a/fs/namei.c > > > > +++ b/fs/namei.c > > > > @@ -3620,6 +3620,8 @@ static int do_open(struct nameidata *nd, > > > > error =3D may_open(idmap, &nd->path, acc_mode, open_flag); > > > > if (!error && !(file->f_mode & FMODE_OPENED)) > > > > error =3D vfs_open(&nd->path, file); > > > > + if (!error) > > > > + error =3D security_file_post_open(file, op->acc_mode); > > >=20 > > > What does it do for O_CREAT? IOW, we managed to create that thing and= we > > > managed to open that thing. Can security_file_post_open() and > > > ima_file_check() fail afterwards even for newly created files? > >=20 > > $ strace touch test-file > > ... > > openat(AT_FDCWD, "test-file", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 066= 6) =3D -1 EPERM (Operation not permitted) >=20 > Ah, meh. I was hoping IMA just wouldn't care about this case. Actually it doesn't. I added code to artifically create the situation (to see what happens if a new LSM does that). Roberto