linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: "Gaurav Kashyap (QUIC)" <quic_gaurkash@quicinc.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>, Jens Axboe <axboe@kernel.dk>,
	Jonathan Corbet <corbet@lwn.net>,
	Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Asutosh Das <quic_asutoshd@quicinc.com>,
	Ritesh Harjani <ritesh.list@gmail.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Avri Altman <avri.altman@wdc.com>,
	Bart Van Assche <bvanassche@acm.org>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Theodore Y. Ts'o" <tytso@mit.edu>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	"manivannan.sadhasivam@linaro.org"
	<manivannan.sadhasivam@linaro.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dm-devel@lists.linux.dev" <dm-devel@lists.linux.dev>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-fscrypt@vger.kernel.org" <linux-fscrypt@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	"bartosz.golaszewski" <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v6 09/17] soc: qcom: ice: add HWKM support to the ICE driver
Date: Sat, 21 Sep 2024 12:49:39 -0700	[thread overview]
Message-ID: <20240921194939.GB2187@quark.localdomain> (raw)
In-Reply-To: <egtwyk2rp3mtnw2ry6npq5xjfhjvtnymbxy66zevtdi7yvaav4@gcnmrmtqro4b>

Hi Dmitry,

On Fri, Sep 13, 2024 at 03:21:07PM +0300, Dmitry Baryshkov wrote:
> > > > > > > Once ICE has moved to a HWKM mode, the firmware key programming
> > > > > > currently does not support raw keys.
> > > > > > > This support is being added for the next Qualcomm chipset in Trustzone to
> > > > > > support both at he same time, but that will take another year or two to hit
> > > > > > the market.
> > > > > > > Until that time, due to TZ (firmware) limitations , the driver can only
> > > > > > support one or the other.
> > > > > > >
> > > > > > > We also cannot keep moving ICE modes, due to the HWKM enablement
> > > > > > being a one-time configurable value at boot.
> > > > > >
> > > > > > So the init of HWKM should be delayed until the point where the user tells if
> > > > > > HWKM or raw keys should be used.
> > > > >
> > > > > Ack.
> > > > > I'll work with Bartosz to look into moving to HWKM mode only during the first key program request
> > > > >
> > > >
> > > > That would mean the driver would have to initially advertise support for both
> > > > HW-wrapped keys and raw keys, and then it would revoke the support for one of
> > > > them later (due to the other one being used).  However, runtime revocation of
> > > > crypto capabilities is not supported by the blk-crypto framework
> > > > (Documentation/block/inline-encryption.rst), and there is no clear path to
> > > > adding such support.  Upper layers may have already checked the crypto
> > > > capabilities and decided to use them.  It's too late to find out that the
> > > > support was revoked in the middle of an I/O request.  Upper layer code
> > > > (blk-crypto, fscrypt, etc.) is not prepared for this.  And even if it was, the
> > > > best it could do is cleanly fail the I/O, which is too late as e.g. it may
> > > > happen during background writeback and cause user data to be thrown away.
> > > 
> > > Can we check crypto capabilities when the user sets the key?
> > 
> > I think you mean when a key is programmed into a keyslot?  That happens during
> > I/O, which is too late as I've explained above.
> > 
> > > Compare this to the actual HSM used to secure communication or
> > > storage. It has certain capabilities, which can be enumerated, etc.
> > > But then at the time the user sets the key it is perfectly normal to
> > > return an error because HSM is out of resources. It might even have
> > > spare key slots, but it might be not enough to be able to program the
> > > required key (as a really crazy example, consider the HSM having at
> > > this time a single spare DES key slot, while the user wants to program
> > > 3DES key).
> > 
> > That isn't how the kernel handles inline encryption keyslots.  They are only
> > programmed as needed for I/O.  If they are all in-use by pending I/O requests,
> > then the kernel waits for an I/O request to finish and reprograms the keyslot it
> > was using.  There is never an error reported due to lack of keyslots.
> 
> Does that mean that the I/O can be outstanding for the very long period
> of time? Or that if the ICE hardware has just a single keyslot, but
> there are two concurrent I/O processes using two different keys, the
> framework will be constantly swapping the keys programmed to the HW?

Yes for both.  Of course, system designers are supposed to put in enough
keyslots for this to not be much of a problem.

So, the "wait for a keyslot" logic in the block layer is necessary in general so
that applications don't unnecessarily get I/O errors.  But in a properly tuned
system this logic should be rarely executed.

And in cases where the keyslots really are a bottleneck, users can of course
just use software encryption instead.

Note that the number of keyslots is reported in sysfs.

> I think it might be prefereable for the drivers and the framework to
> support "preprogramming" of the keys, when the key is programmed to the
> hardware when it is set by the user.

This doesn't sound particularly useful.  If there are always enough keyslots,
then keyslots never get evicted and there is no advantage to this.  If there are
*not* always enough keyslots, then it's sometimes necessary to evict keyslots,
so it would not be desirable to have them permanently reserved.

It could make sense to have some sort of hints mechanism, where frequently-used
keys can be marked as high-priority to keep programmed in a keyslot.  I don't
see much of a need for this though, given that the eviction policy is already
LRU, so it already prefers to keep frequently-used keys in a keyslot.

> Another option might be to let the drivers validate the keys being set
> by userspace. This way in our case the driver might report that it
> supports both raw and wrapped keys, but start rejecting the keys once
> it gets notified that the user has programmed other kind of keys. This
> way key setup can fail, but the actual I/O can not. WDYT?

Well, that has the same effect as the crypto capabilities check which is already
done.  The problem is that your proposal effectively revokes a capability, and
that is racy.

- Eric

  reply	other threads:[~2024-09-21 19:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 18:07 [PATCH v6 00/17] Hardware wrapped key support for QCom ICE and UFS core Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 01/17] blk-crypto: add basic hardware-wrapped key support Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 02/17] blk-crypto: show supported key types in sysfs Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 03/17] blk-crypto: add ioctls to create and prepare hardware-wrapped keys Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 04/17] fscrypt: add support for " Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 05/17] ice, ufs, mmc: use the blk_crypto_key struct when programming the key Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 06/17] firmware: qcom: scm: add a call for deriving the software secret Bartosz Golaszewski
2024-09-09 11:23   ` Konrad Dybcio
2024-09-26 14:45     ` Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 07/17] firmware: qcom: scm: add calls for creating, preparing and importing keys Bartosz Golaszewski
2024-09-09 11:24   ` Konrad Dybcio
2024-09-06 18:07 ` [PATCH v6 08/17] firmware: qcom: scm: add a call for checking wrapped key support Bartosz Golaszewski
2024-09-09 11:25   ` Konrad Dybcio
2024-09-06 18:07 ` [PATCH v6 09/17] soc: qcom: ice: add HWKM support to the ICE driver Bartosz Golaszewski
2024-09-06 22:07   ` Dmitry Baryshkov
2024-09-09  8:58     ` Neil Armstrong
2024-09-09  9:44       ` Dmitry Baryshkov
2024-09-10  0:51         ` Gaurav Kashyap (QUIC)
2024-09-10  6:28           ` Dmitry Baryshkov
2024-09-12 22:17             ` Gaurav Kashyap (QUIC)
2024-09-12 23:17               ` Eric Biggers
2024-09-13  4:28                 ` Dmitry Baryshkov
2024-09-13  4:57                   ` Eric Biggers
2024-09-13 12:21                     ` Dmitry Baryshkov
2024-09-21 19:49                       ` Eric Biggers [this message]
2024-09-21 22:33                         ` Dmitry Baryshkov
2024-09-13  7:23                 ` Neil Armstrong
2024-09-06 18:07 ` [PATCH v6 10/17] soc: qcom: ice: add support for hardware wrapped keys Bartosz Golaszewski
2024-09-09 11:51   ` Konrad Dybcio
2024-09-06 18:07 ` [PATCH v6 11/17] soc: qcom: ice: add support for generating, importing and preparing keys Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 12/17] ufs: core: add support for wrapped keys to UFS core Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 13/17] ufs: core: add support for deriving the software secret Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 14/17] ufs: core: add support for generating, importing and preparing keys Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 15/17] ufs: host: add support for wrapped keys in QCom UFS Bartosz Golaszewski
2024-09-06 18:07 ` [PATCH v6 16/17] ufs: host: add a callback for deriving software secrets and use it Bartosz Golaszewski
2024-09-09 11:56   ` Konrad Dybcio
2024-09-06 18:07 ` [PATCH v6 17/17] ufs: host: add support for generating, importing and preparing wrapped keys Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240921194939.GB2187@quark.localdomain \
    --to=ebiggers@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=adrian.hunter@intel.com \
    --cc=agk@redhat.com \
    --cc=alim.akhtar@samsung.com \
    --cc=andersson@kernel.org \
    --cc=avri.altman@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brauner@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=bvanassche@acm.org \
    --cc=corbet@lwn.net \
    --cc=dm-devel@lists.linux.dev \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=martin.petersen@oracle.com \
    --cc=mpatocka@redhat.com \
    --cc=neil.armstrong@linaro.org \
    --cc=quic_asutoshd@quicinc.com \
    --cc=quic_gaurkash@quicinc.com \
    --cc=ritesh.list@gmail.com \
    --cc=snitzer@kernel.org \
    --cc=tytso@mit.edu \
    --cc=ulf.hansson@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).