Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5028996rwb; Tue, 8 Aug 2023 19:15:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdki1NtumEeDZbtxhBBFVO+gbUG6IMYMP2o76tXWdnEdjQua6Hd7RBy2bpKpCRRVYu+eXA X-Received: by 2002:a05:6a21:7794:b0:13b:79dc:4538 with SMTP id bd20-20020a056a21779400b0013b79dc4538mr1134969pzc.62.1691547299760; Tue, 08 Aug 2023 19:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691547299; cv=none; d=google.com; s=arc-20160816; b=C2K83GkwyheIT93KM1T46fVy0t05NgTGcHLKUqLNPtlZvHSwDBT5I7x/4gQb0h1PUb uI1Lt+SlP6MOQXGWhuAvTce+VDG9956BFAEu+2GEzXZEMCY27697rKcVT8tZrLH1mANF 0q2Y+IELSilGPjmxMotsdRQ2TkGRCFXSemuIJPbMrOZpD9GeFZq+RcEKDX2qHerIuijW y/GJCEYl1lR73/upQilkbt7njlV7Qh61Vjd953LBk3M4zjrF8knFk9nYmTIhOV0lFpkS WGvIgS2wey7YeJ6CgQdahGVfB4n9cL2fJAZZFmrEn4AJ5U8eZi20hXcTTwoyNJU5sEAW y6ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=sVCat3a1M7KHdlESd70oA1x2KXrxJ+56GtFSeTDlhcM=; fh=vEfHg3CK0W7amWssIpcDhqBCd9Zt3hd+721tXMmpyVo=; b=KSD/rWjB/3M3ln663LulMcqAFNVFVVCP5NEYv2C2ynQEj5ZA5tHflQqKwONjDaTp40 5I74Cod1QmRRW47npW7VafMfJfOe6//vH7pw0giUaBtzrr8TSnFBKjFciQPuqt1F6lfR VptaI3aLEP8Ie0MbtIxLsdKLMsMFwJrLsOEaoLNrub0FrxOm6w9fyVXUX/k+MttgBMif MmyaDL5pvhHu3F9WpKXjrb2+8kvTXUZZtCOsR13kTkjn+/1LU8WfOZp/7ufaf1x4J4oe 8dj5zvNrSRGhJF8GbFTg/Dyk1dkvSQYpj5xLUnseXrYSFmXTUDUaYTv4iPnM/XPsXrAu JLdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=IKGEzYVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020a1709027e8900b001b694ecf48fsi5363415pla.71.2023.08.08.19.14.48; Tue, 08 Aug 2023 19:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=IKGEzYVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230369AbjHHWpG (ORCPT + 99 others); Tue, 8 Aug 2023 18:45:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjHHWpF (ORCPT ); Tue, 8 Aug 2023 18:45:05 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46A97100; Tue, 8 Aug 2023 15:45:04 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1052) id ACC3A20FC0D2; Tue, 8 Aug 2023 15:45:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ACC3A20FC0D2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1691534703; bh=sVCat3a1M7KHdlESd70oA1x2KXrxJ+56GtFSeTDlhcM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IKGEzYVtmP2d5RXQGvuDn1I/QZ4sOzZi4K/A2GFZ2iulDRvmRtjOIZiRVuMKczceS 0CiDLnNBQ2LUBMhDJBdn1PQPlunEfC8CXQzTGInv/hBg/Ilpo2DmC4rg8xJgCfKGlU /LGb9xCJTxmrboncvvC5Grxc+B/9dleXOZ5FNzVQ= Date: Tue, 8 Aug 2023 15:45:03 -0700 From: Fan Wu To: Paul Moore Cc: Mike Snitzer , 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, eparis@redhat.com, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, audit@vger.kernel.org, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Deven Bowers Subject: Re: [RFC PATCH v10 11/17] dm-verity: consume root hash digest and signature data via LSM hook Message-ID: <20230808224503.GA20095@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1687986571-16823-1-git-send-email-wufan@linux.microsoft.com> <1687986571-16823-12-git-send-email-wufan@linux.microsoft.com> <20230712034319.GA17642@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 25, 2023 at 04:43:48PM -0400, Paul Moore wrote: > On Tue, Jul 11, 2023 at 11:43???PM Fan Wu wrote: > > On Fri, Jul 07, 2023 at 10:53:45AM -0400, Mike Snitzer wrote: > > ... > > > > Both of your calls to security_bdev_setsecurity() to set your blobs in > > > the bdev are suspect because you're doing so from the verity_ctr(). > > > The mapped_device has 2 dm_table slots (active and inactive). The > > > verity_ctr() becomes part of the inactive slot, there is an extra step > > > to bind the inactive table to the active table. > > > > > > This leads to you changing the blobs in the global bdev _before_ the > > > table is actually active. It is possible that the inactive table will > > > simply be removed and the DM verity device put back in service; > > > leaving your blob(s) in the bdev inconsistent. > > > > > > This issue has parallels to how we need to defer changing the global > > > queue_limits associated with a request_queue until _after_ all table > > > loading is settled and then the update is done just before resuming > > > the DM device (mapped_device) -- see dm_table_set_restrictions(). > > > > > > Unfortunately, this feels like it may require a new hook in the > > > target_type struct (e.g. ->finalize()) > > > > Thanks for pointing out this issue. We were calling security_bdev_setsecurity() > > because the roothash signature data is only available in verity_ctr() > > and it is discarded after verity_ctr() finishes. > > After digging deeper into the table_load, I realized that we were indeed > > wrong here. > > > > Based on my understanding of your suggestion, it seems that the correct > > approach would be to save the roothash signature into the struct dm_target > Sorry for the delay in responding. It took me a while to test out the design idea suggested by Mike. The current implementation is indeed incorrect. However, I've been able to develop a working prototype that addresses the problem identified in the existing implementation. I still need some additional time to fine-tune and clean up the prototype. My goal is to have everything ready and send it out next month. > Would you be doing this with a LSM hook, or would this live in the > device mapper layer? > In my implemention, it is a new hook in the device mapper layer. The hook is triggered just before activating an inactive table of a mapped device. So in our case, we use the hook to attached the dm-verity's roothash metadata to the block_device struct of mapped device. > > and then invoke security_bdev_setsecurity() before activating > > the inactive table in the __bind function (where dm_table_set_restrictions is called). > > > > To facilitate this process, it seems appropriate to introduce a new hook > > called finalize() within the struct target_type. This hook would enable > > targets to define tasks that need to be completed before activating > > a new table. > > > > In our specific case, we would add a finalize hook to the dm-verity module, > > allowing us to call security_bdev_setsecurity() and associate the roothash > > information in the struct dm_target with the struct block_device of > > the struct mapped_device. Is this correct? > > Where would the finalize() hook be called? It is in the __bind function in drivers/md/dm.c, calling just before rcu_assign_pointer(md->map, (void *)t) which activates the inactive table. -Fan