Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1014818lqb; Sat, 25 May 2024 02:03:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXi6jpfvBJO4IMinSZJc8QVFypRMxHFVte7CCxyaSIk7DlwEaw2PnLSbpCcaN6JDAf0Ei3qhQ66weAIvwV0fCz5F0ER4DLTPcnEvtEi2Q== X-Google-Smtp-Source: AGHT+IE7se71VsjRPd4BsB8H+kHEGZV93HswOISKF4bAN2sFyZoECz+5WQqHmks7gXFxNIMQdjrD X-Received: by 2002:a05:620a:1da7:b0:792:905f:667e with SMTP id af79cd13be357-794ab0a312dmr528909485a.28.1716627781014; Sat, 25 May 2024 02:03:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716627780; cv=pass; d=google.com; s=arc-20160816; b=RFi9a6pcms3/pbdlaDM3hvSYFnReZVKOVECzLQz7ezk4UWRx+3DcASzDtSsMfJMZDZ pmpQVnyA96wHKNUX6VNc81pn0MtUG9iUide5E7gyQ8S1wotBby3bkQ3KtoKJDt7D4ITe gJiZdRArFxV95icua9pp4y6CtgGNmeN0l3TCEuNmkLURKocf/Lbm3YFlsuo86Rbbb1LD mP4xRkABGkhXmPR7VeceVg7qTdkmxkKxRXTCog6P4GouzOpuAmStvCNCFGwJ42qwFy7u j+rcFU+hwBtkZRvFlypq57X6p7Jv8b4SjtAJBBZq1tNzDirjJx960uXSVi6IQ7gEm+vL gMRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=1J0rKNy85PKDwGmqMPeEERwZIA8DQYDYUviYS11PQQ8=; fh=ZBOuryk72t6/6As/lnpz/KROgNIxOQ7hYKVXnWWDuj8=; b=H9QNtutQK3O3vegYKzoG6AnuivZ07SohmzDZ7jHu2Am0Fq1BuXCkr6JNlOrh6XokYI 3sg+kbVKehx1r0Zj5BOgB7CXxbbC5EgJcoR2exl5zoCe+jO79DEX3frxdRTiA6Q3zT6I 5WVeSxfv1xlNWmCWiUarsNscpAMWZhCbMiaXydXu2wny6zROGrjCchj/75PxOE82zDsO K605L1rW3m4ksSLLcW/e6m7oTXnqHuOys9+S+u4B9eouEAGPssxgzdP60t5bRVhEneyS rOJ6RcIHHYXncMH2xkqgCqmqlrCXbcqsaX+WGhRWUM7JzqW8I1SAITD0vxz/EIE09R6D ZFKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BN7VFvu6; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-189310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd61354si326605985a.759.2024.05.25.02.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 02:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BN7VFvu6; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-189310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AB0AE1C20B33 for ; Sat, 25 May 2024 09:03:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2F8D210FF; Sat, 25 May 2024 09:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BN7VFvu6" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 D6EC120315 for ; Sat, 25 May 2024 09:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716627770; cv=none; b=LmsB1GzI8VcvkkBQ9hVtAfnS7m+bU5TRqe2Lx8Tw6VTMkZ+PoghGdsqdus5vBgBi6mgIjcVLtj3LhNNcRg0UkUacwUyfVYEbfIL61UpbeARP9sm2gtaIEFZcatYnYEFnKmdoY8hw/AAB2olHrn3XTW/7fcUr2itVlq2O38FS6U8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716627770; c=relaxed/simple; bh=WXZ3aTu/mmAKPxVAoAnX/sGVd7wKZ9FD/gY3DymuZY8=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=T1IaTyKw3YwO5tM0Du1nwHPdsTk2K1TVPOidzk1ESDW0jf2S8Kg7nsEBnueWxpK0bibs+3btSFfrszgnAxVR5q7WzMBZ3DC2VcVbzvSfwle+TzWYA8wNyG32o2wbkg221rPOzo4MYGBZg02Y3IiqGuPOIkTJwyw9pAYukl0wnAA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BN7VFvu6; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716627767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1J0rKNy85PKDwGmqMPeEERwZIA8DQYDYUviYS11PQQ8=; b=BN7VFvu6VmVOOiBFc3iX49uiVs4NUajryx2p1z60AeymFQN1xDuyiKaWHIUTa8eHeWB6yX vcrjh3D7mLl9/WUkZBFtsXyE1wirE+XLiOUBfVxmnTaaWKLFmn2is0vhnMs1gxiKwlJZ/f cwWADfRBWsWIgQ2onpW/2YcgldUn5NQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-egEkEatAOuOAHeJGROQ6tw-1; Sat, 25 May 2024 05:02:41 -0400 X-MC-Unique: egEkEatAOuOAHeJGROQ6tw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67D8F101A525; Sat, 25 May 2024 09:02:40 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3736200B4CF; Sat, 25 May 2024 09:02:39 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id C2A9D30C1C33; Sat, 25 May 2024 09:02:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id BE9F23FB52; Sat, 25 May 2024 11:02:39 +0200 (CEST) Date: Sat, 25 May 2024 11:02:39 +0200 (CEST) From: Mikulas Patocka To: Fan Wu cc: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, eparis@redhat.com, paul@paul-moore.com, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, fsverity@lists.linux.dev, linux-block@vger.kernel.org, dm-devel@lists.linux.dev, audit@vger.kernel.org, linux-kernel@vger.kernel.org, Deven Bowers Subject: Re: [PATCH v19 12/20] dm verity: expose root hash digest and signature data to LSMs In-Reply-To: <1716583609-21790-13-git-send-email-wufan@linux.microsoft.com> Message-ID: References: <1716583609-21790-1-git-send-email-wufan@linux.microsoft.com> <1716583609-21790-13-git-send-email-wufan@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Reviewed-by: Mikulas Patocka On Fri, 24 May 2024, Fan Wu wrote: > From: Deven Bowers > > dm-verity provides a strong guarantee of a block device's integrity. As > a generic way to check the integrity of a block device, it provides > those integrity guarantees to its higher layers, including the filesystem > level. > > An LSM that control access to a resource on the system based on the > available integrity claims can use this transitive property of > dm-verity, by querying the underlying block_device of a particular > file. > > The digest and signature information need to be stored in the block > device to fulfill the next requirement of authorization via LSM policy. > This will enable the LSM to perform revocation of devices that are still > mounted, prohibiting execution of files that are no longer authorized > by the LSM in question. > > This patch adds two security hook calls in dm-verity to expose the > dm-verity roothash and the roothash signature to LSMs via preresume > callback. The hook calls are depended on CONFIG_SECURITY. > > Signed-off-by: Deven Bowers > Signed-off-by: Fan Wu > --- > v2: > + No Changes > > v3: > + No changes > > v4: > + No changes > > v5: > + No changes > > v6: > + Fix an improper cleanup that can result in > a leak > > v7: > + Squash patch 08/12, 10/12 to [11/16] > + Use part0 for block_device, to retrieve the block_device, when > calling security_bdev_setsecurity > > v8: > + Undo squash of 08/12, 10/12 - separating drivers/md/ from > security/ & block/ > + Use common-audit function for dmverity_signature. > + Change implementation for storing the dm-verity digest to use the > newly introduced dm_verity_digest structure introduced in patch > 14/20. > + Create new structure, dm_verity_digest, containing digest algorithm, > size, and digest itself to pass to the LSM layer. V7 was missing the > algorithm. > + Create an associated public header containing this new structure and > the key values for the LSM hook, specific to dm-verity. > + Additional information added to commit, discussing the layering of > the changes and how the information passed will be used. > > v9: > + No changes > > v10: > + No changes > > v11: > + Add an optional field to save signature > + Move the security hook call to the new finalize hook > > v12: > + No changes > > v13: > + No changes > > v14: > + Correct code format > + Remove unnecessary header and switch to dm_disk() > > v15: > + Refactor security_bdev_setsecurity() to security_bdev_setintegrity() > + Remove unnecessary headers > > v16: > + Use kmemdup to duplicate signature > + Clean up lsm blob data in error case > > v17: > + Switch to depend on CONFIG_SECURITY > + Use new enum name LSM_INT_DMVERITY_SIG_VALID > > v18: > + Amend commit title > + Fix incorrect error handling > + Make signature exposure depends on CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG > + Fix inaccurate comment > + Remove include/linux/dm-verity.h > + use crypto_ahash_alg_name(v->tfm) instead of v->alg_name > > v19: > + Drop finalize callback and switch to preresume callback > + Adding NULL check to avoid kmemdup when sig is NULL > --- > drivers/md/dm-verity-target.c | 108 ++++++++++++++++++++++++++++++++++ > drivers/md/dm-verity.h | 6 ++ > include/linux/security.h | 9 ++- > 3 files changed, 122 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c > index bb5da66da4c1..0a54ce02ea53 100644 > --- a/drivers/md/dm-verity-target.c > +++ b/drivers/md/dm-verity-target.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > > #define DM_MSG_PREFIX "verity" > > @@ -1017,6 +1018,41 @@ static void verity_io_hints(struct dm_target *ti, struct queue_limits *limits) > blk_limits_io_min(limits, limits->logical_block_size); > } > > +#ifdef CONFIG_SECURITY > + > +static int verity_init_sig(struct dm_verity *v, const void *sig, > + size_t sig_size) > +{ > + v->sig_size = sig_size; > + > + if (sig) { > + v->root_digest_sig = kmemdup(sig, v->sig_size, GFP_KERNEL); > + if (!v->root_digest_sig) > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static void verity_free_sig(struct dm_verity *v) > +{ > + kfree(v->root_digest_sig); > +} > + > +#else > + > +static inline int verity_init_sig(struct dm_verity *v, const void *sig, > + size_t sig_size) > +{ > + return 0; > +} > + > +static inline void verity_free_sig(struct dm_verity *v) > +{ > +} > + > +#endif /* CONFIG_SECURITY */ > + > static void verity_dtr(struct dm_target *ti) > { > struct dm_verity *v = ti->private; > @@ -1035,6 +1071,7 @@ static void verity_dtr(struct dm_target *ti) > kfree(v->salt); > kfree(v->root_digest); > kfree(v->zero_digest); > + verity_free_sig(v); > > if (v->tfm) > crypto_free_ahash(v->tfm); > @@ -1434,6 +1471,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) > ti->error = "Root hash verification failed"; > goto bad; > } > + > + r = verity_init_sig(v, verify_args.sig, verify_args.sig_size); > + if (r < 0) { > + ti->error = "Cannot allocate root digest signature"; > + goto bad; > + } > + > v->hash_per_block_bits = > __fls((1 << v->hash_dev_block_bits) / v->digest_size); > > @@ -1584,6 +1628,67 @@ int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsigned i > return 0; > } > > +#ifdef CONFIG_SECURITY > + > +#ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG > + > +static int verity_security_set_signature(struct block_device *bdev, > + struct dm_verity *v) > +{ > + return security_bdev_setintegrity(bdev, > + LSM_INT_DMVERITY_SIG_VALID, > + v->root_digest_sig, > + v->sig_size); > +} > + > +#else > + > +static inline int verity_security_set_signature(struct block_device *bdev, > + struct dm_verity *v) > +{ > + return 0; > +} > + > +#endif /* CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG */ > + > +/* > + * Expose verity target's root hash and signature data to LSMs before resume. > + * > + * Returns 0 on success, or -ENOMEM if the system is out of memory. > + */ > +static int verity_preresume(struct dm_target *ti) > +{ > + struct block_device *bdev; > + struct dm_verity_digest root_digest; > + struct dm_verity *v; > + int r; > + > + v = ti->private; > + bdev = dm_disk(dm_table_get_md(ti->table))->part0; > + root_digest.digest = v->root_digest; > + root_digest.digest_len = v->digest_size; > + root_digest.alg = crypto_ahash_alg_name(v->tfm); > + > + r = security_bdev_setintegrity(bdev, LSM_INT_DMVERITY_ROOTHASH, &root_digest, > + sizeof(root_digest)); > + if (r) > + return r; > + > + r = verity_security_set_signature(bdev, v); > + if (r) > + goto bad; > + > + return 0; > + > +bad: > + > + security_bdev_setintegrity(bdev, LSM_INT_DMVERITY_ROOTHASH, NULL, 0); > + > + return r; > +} > + > +#endif /* CONFIG_SECURITY */ > + > static struct target_type verity_target = { > .name = "verity", > .features = DM_TARGET_SINGLETON | DM_TARGET_IMMUTABLE, > @@ -1596,6 +1701,9 @@ static struct target_type verity_target = { > .prepare_ioctl = verity_prepare_ioctl, > .iterate_devices = verity_iterate_devices, > .io_hints = verity_io_hints, > +#ifdef CONFIG_SECURITY > + .preresume = verity_preresume, > +#endif /* CONFIG_SECURITY */ > }; > module_dm(verity); > > diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h > index 20b1bcf03474..2de89e0d555b 100644 > --- a/drivers/md/dm-verity.h > +++ b/drivers/md/dm-verity.h > @@ -43,6 +43,9 @@ struct dm_verity { > u8 *root_digest; /* digest of the root block */ > u8 *salt; /* salt: its size is salt_size */ > u8 *zero_digest; /* digest for a zero block */ > +#ifdef CONFIG_SECURITY > + u8 *root_digest_sig; /* signature of the root digest */ > +#endif /* CONFIG_SECURITY */ > unsigned int salt_size; > sector_t data_start; /* data offset in 512-byte sectors */ > sector_t hash_start; /* hash start in blocks */ > @@ -56,6 +59,9 @@ struct dm_verity { > bool hash_failed:1; /* set if hash of any block failed */ > bool use_bh_wq:1; /* try to verify in BH wq before normal work-queue */ > unsigned int digest_size; /* digest size for the current hash algorithm */ > +#ifdef CONFIG_SECURITY > + unsigned int sig_size; /* root digest signature size */ > +#endif /* CONFIG_SECURITY */ > unsigned int ahash_reqsize;/* the size of temporary space for crypto */ > enum verity_mode mode; /* mode for handling verification errors */ > unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ > diff --git a/include/linux/security.h b/include/linux/security.h > index a64e83622c7c..09c80326518f 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -83,8 +83,15 @@ enum lsm_event { > LSM_POLICY_CHANGE, > }; > > +struct dm_verity_digest { > + const char *alg; > + const u8 *digest; > + size_t digest_len; > +}; > + > enum lsm_integrity_type { > - __LSM_INT_MAX > + LSM_INT_DMVERITY_SIG_VALID, > + LSM_INT_DMVERITY_ROOTHASH, > }; > > /* > -- > 2.44.0 >