From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Harald Freudenberger <freude@linux.ibm.com>,
Holger Dengler <dengler@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Sasha Levin <sashal@kernel.org>,
gor@linux.ibm.com, agordeev@linux.ibm.com,
linux-s390@vger.kernel.org
Subject: [PATCH AUTOSEL 6.11 17/30] s390/ap: Fix CCA crypto card behavior within protected execution environment
Date: Wed, 23 Oct 2024 10:29:42 -0400 [thread overview]
Message-ID: <20241023143012.2980728-17-sashal@kernel.org> (raw)
In-Reply-To: <20241023143012.2980728-1-sashal@kernel.org>
From: Harald Freudenberger <freude@linux.ibm.com>
[ Upstream commit 78f636e82b2288462498e235dc5a886426ce5dd7 ]
A crypto card comes in 3 flavors: accelerator, CCA co-processor or
EP11 co-processor. Within a protected execution environment only the
accelerator and EP11 co-processor is supported. However, it is
possible to set up a KVM guest with a CCA card and run it as a
protected execution guest. There is nothing at the host side which
prevents this. Within such a guest, a CCA card is shown as "illicit"
and you can't do anything with such a crypto card.
Regardless of the unsupported CCA card within a protected execution
guest there are a couple of user space applications which
unconditional try to run crypto requests to the zcrypt device
driver. There was a bug within the AP bus code which allowed such a
request to be forwarded to a CCA card where it is finally
rejected and the driver reacts with -ENODEV but also triggers an AP
bus scan. Together with a retry loop this caused some kind of "hang"
of the KVM guest. On startup it caused timeouts and finally led the
KVM guest startup fail. Fix that by closing the gap and make sure a
CCA card is not usable within a protected execution environment.
Another behavior within an protected execution environment with CCA
cards was that the se_bind and se_associate AP queue sysfs attributes
where shown. The implementation unconditional always added these
attributes. Fix that by checking if the card mode is supported within
a protected execution environment and only if valid, add the attribute
group.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/s390/crypto/ap_bus.c | 3 +--
drivers/s390/crypto/ap_bus.h | 2 +-
drivers/s390/crypto/ap_queue.c | 28 ++++++++++++++++++++--------
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index 3ba4e1c5e15df..57aefccbb8556 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1865,13 +1865,12 @@ static inline void ap_scan_domains(struct ap_card *ac)
}
/* if no queue device exists, create a new one */
if (!aq) {
- aq = ap_queue_create(qid, ac->ap_dev.device_type);
+ aq = ap_queue_create(qid, ac);
if (!aq) {
AP_DBF_WARN("%s(%d,%d) ap_queue_create() failed\n",
__func__, ac->id, dom);
continue;
}
- aq->card = ac;
aq->config = !decfg;
aq->chkstop = chkstop;
aq->se_bstate = hwinfo.bs;
diff --git a/drivers/s390/crypto/ap_bus.h b/drivers/s390/crypto/ap_bus.h
index 0b275c7193196..f4622ee4d8947 100644
--- a/drivers/s390/crypto/ap_bus.h
+++ b/drivers/s390/crypto/ap_bus.h
@@ -272,7 +272,7 @@ int ap_test_config_usage_domain(unsigned int domain);
int ap_test_config_ctrl_domain(unsigned int domain);
void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *ap_msg);
-struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type);
+struct ap_queue *ap_queue_create(ap_qid_t qid, struct ap_card *ac);
void ap_queue_prepare_remove(struct ap_queue *aq);
void ap_queue_remove(struct ap_queue *aq);
void ap_queue_init_state(struct ap_queue *aq);
diff --git a/drivers/s390/crypto/ap_queue.c b/drivers/s390/crypto/ap_queue.c
index 1f647ffd6f4db..dcd1590c0f81f 100644
--- a/drivers/s390/crypto/ap_queue.c
+++ b/drivers/s390/crypto/ap_queue.c
@@ -22,6 +22,11 @@ static void __ap_flush_queue(struct ap_queue *aq);
* some AP queue helper functions
*/
+static inline bool ap_q_supported_in_se(struct ap_queue *aq)
+{
+ return aq->card->hwinfo.ep11 || aq->card->hwinfo.accel;
+}
+
static inline bool ap_q_supports_bind(struct ap_queue *aq)
{
return aq->card->hwinfo.ep11 || aq->card->hwinfo.accel;
@@ -1104,18 +1109,19 @@ static void ap_queue_device_release(struct device *dev)
kfree(aq);
}
-struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type)
+struct ap_queue *ap_queue_create(ap_qid_t qid, struct ap_card *ac)
{
struct ap_queue *aq;
aq = kzalloc(sizeof(*aq), GFP_KERNEL);
if (!aq)
return NULL;
+ aq->card = ac;
aq->ap_dev.device.release = ap_queue_device_release;
aq->ap_dev.device.type = &ap_queue_type;
- aq->ap_dev.device_type = device_type;
- // add optional SE secure binding attributes group
- if (ap_sb_available() && is_prot_virt_guest())
+ aq->ap_dev.device_type = ac->ap_dev.device_type;
+ /* in SE environment add bind/associate attributes group */
+ if (ap_is_se_guest() && ap_q_supported_in_se(aq))
aq->ap_dev.device.groups = ap_queue_dev_sb_attr_groups;
aq->qid = qid;
spin_lock_init(&aq->lock);
@@ -1196,10 +1202,16 @@ bool ap_queue_usable(struct ap_queue *aq)
}
/* SE guest's queues additionally need to be bound */
- if (ap_q_needs_bind(aq) &&
- !(aq->se_bstate == AP_BS_Q_USABLE ||
- aq->se_bstate == AP_BS_Q_USABLE_NO_SECURE_KEY))
- rc = false;
+ if (ap_is_se_guest()) {
+ if (!ap_q_supported_in_se(aq)) {
+ rc = false;
+ goto unlock_and_out;
+ }
+ if (ap_q_needs_bind(aq) &&
+ !(aq->se_bstate == AP_BS_Q_USABLE ||
+ aq->se_bstate == AP_BS_Q_USABLE_NO_SECURE_KEY))
+ rc = false;
+ }
unlock_and_out:
spin_unlock_bh(&aq->lock);
--
2.43.0
next prev parent reply other threads:[~2024-10-23 14:30 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 14:29 [PATCH AUTOSEL 6.11 01/30] 9p: v9fs_fid_find: also lookup by inode if not found dentry Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 02/30] 9p: Avoid creating multiple slab caches with the same name Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 03/30] selftests/bpf: Verify that sync_linked_regs preserves subreg_def Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 04/30] nvmet-passthru: clear EUID/NGUID/UUID while using loop target Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 05/30] irqchip/ocelot: Fix trigger register address Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 06/30] pinctrl: aw9523: add missing mutex_destroy Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 07/30] pinctrl: intel: platform: Add Panther Lake to the list of supported Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 08/30] nvme: tcp: avoid race between queue_lock lock and destroy Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 09/30] block: Fix elevator_get_default() checking for NULL q->tag_set Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 10/30] HID: multitouch: Add support for B2402FVA track point Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 11/30] HID: multitouch: Add quirk for HONOR MagicBook Art 14 touchpad Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 12/30] iommu/arm-smmu: Clarify MMU-500 CPRE workaround Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 13/30] nvme: disable CC.CRIME (NVME_CC_CRIME) Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 14/30] bpf: use kvzmalloc to allocate BPF verifier environment Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 15/30] crypto: api - Fix liveliness check in crypto_alg_tested Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 16/30] crypto: marvell/cesa - Disable hash algorithms Sasha Levin
2024-10-23 14:29 ` Sasha Levin [this message]
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 18/30] sound: Make CONFIG_SND depend on INDIRECT_IOMEM instead of UML Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 19/30] drm/vmwgfx: Limit display layout ioctl array size to VMWGFX_NUM_DISPLAY_UNITS Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 20/30] selftests/bpf: Assert link info uprobe_multi count & path_size if unset Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 21/30] RDMA/siw: Add sendpage_ok() check to disable MSG_SPLICE_PAGES Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 22/30] ALSA: hda/tas2781: Add new quirk for Lenovo, ASUS, Dell projects Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 23/30] kasan: Disable Software Tag-Based KASAN with GCC Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 24/30] nvme-multipath: defer partition scanning Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 25/30] drm/amdkfd: Accounting pdd vram_usage for svm Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 26/30] powerpc/powernv: Free name on error in opal_event_init() Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 27/30] net: phy: mdio-bcm-unimac: Add BCM6846 support Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 28/30] drm/xe/query: Increase timestamp width Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 29/30] nvme-loop: flush off pending I/O while shutting down loop controller Sasha Levin
2024-10-23 14:29 ` [PATCH AUTOSEL 6.11 30/30] nvme: make keep-alive synchronous operation Sasha Levin
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=20241023143012.2980728-17-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=dengler@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.