Close speculative mem read possibility
Subsystems (2)
Harald Freudenberger
maintainerv2 cover Close speculative mem read possibility
The domain value is extracted from a given CCA or EP11 ioctl struct when a CPRB is about to be sent. Thus this is a user controlled value. Under some special conditions (custom device node used, administrative load) this value is used as an array index after bounds checking, but without speculation barrier.
Add the missing array_index_nospec() call to prevent speculative execution where this domain value is used.
Changelog:
v1: initial version
v2: Rephrased patch header text, added Finn's Reviewed-by, no code changes.
Harald Freudenberger (1):
s390/zcrypt: Close speculative mem read possibility
drivers/s390/crypto/zcrypt_api.c | 2 ++ 1 file changed, 2 insertions(+)
Signature · 1 line
2.43.0
Harald Freudenberger
maintainerPATCH v2 1/1 s390/zcrypt: Close speculative mem read possibility
The domain value is extracted from a given CCA or EP11 ioctl struct when a CPRB is about to be sent. Thus this is a user controlled value. Under some special conditions (custom device node used, administrative load) this value is used as an array index after bounds checking, but without speculation barrier.
Add the missing array_index_nospec() call to prevent speculative execution where this domain value is used.
--- drivers/s390/crypto/zcrypt_api.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/s390/crypto/zcrypt_api.c +2 -0
@@ -879,6 +879,7 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,if (perms != &ap_perms && domain <AP_DOMAINS ) {if (ap_msg.flags &AP_MSG_FLAG_ADMIN ) { + domain =array_index_nospec (domain,AP_DOMAINS );if (!test_bit_inv (domain, perms->adm)) { rc = -ENODEV ; goto out;
@@ -1079,6 +1080,7 @@ static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms,if (perms != &ap_perms && domain <AUTOSEL_DOM ) {if (ap_msg.flags &AP_MSG_FLAG_ADMIN ) { + domain =array_index_nospec (domain,AP_DOMAINS );if (!test_bit_inv (domain, perms->adm)) { rc = -ENODEV ; goto out;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 1/1] s390/zcrypt: Close speculative mem read possibility
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] In _zcrypt_send_ep11_cprb, array_index_nospec() is used without a prior bounds check against AP_DOMAINS, silently aliasing out-of-bounds domains to domain 0 and bypassing administrative permission checks.
Pre-existing issues:
- [High] Administrative CPRBs with domain == AUTOSEL_DOM completely bypass the perms->adm permission check in _zcrypt_send_cprb and _zcrypt_send_ep11_cprb. --
--- Patch [1]: [PATCH v2 1/1] s390/zcrypt: Close speculative mem read possibility --- commit de8272723358b7baff06b29b44fe219b26350d5e
Author: Harald Freudenberger <[email protected]>
s390/zcrypt: Close speculative mem read possibility
This patch addresses a speculative execution out-of-bounds read by adding array_index_nospec() to the domain value extracted from user-controlled CPRB structs before it is used as an array index.
drivers/s390/crypto/zcrypt_api.c static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms, · line 880
Quoted 7 lines
drivers/s390/crypto/zcrypt_api.c +0
-0@@ -879,6 +879,7 @@ static long _zcrypt_send_cprb(u32 xflags, struct ap_perms *perms,if (perms != &ap_perms && domain <AP_DOMAINS ) {
[Severity: High]
This is a pre-existing issue, but does this logic allow administrative CPRBs with domain == AUTOSEL_DOM to bypass the perms->adm permission check entirely?
If a user submits a CPRB request with an administrative command code and sets the target domain to AUTOSEL_DOM, this condition evaluates to false.
The perms->adm evaluation is skipped, and the kernel later selects a queue based solely on the user's usage permissions in zcrypt_check_queue().
Quoted 5 lines
drivers/s390/crypto/zcrypt_api.c +1
-0if (ap_msg.flags &AP_MSG_FLAG_ADMIN ) { + domain =array_index_nospec (domain,AP_DOMAINS );if (!test_bit_inv (domain, perms->adm)) { rc = -ENODEV ; goto out;
[ ... ]
drivers/s390/crypto/zcrypt_api.c static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms, · line 1081
Quoted 3 lines
drivers/s390/crypto/zcrypt_api.c +0
-0@@ -1079,6 +1080,7 @@ static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms,if (perms != &ap_perms && domain <AUTOSEL_DOM ) {
[Severity: High]
This is a pre-existing issue, but does this similarly skip the admin check for EP11 CPRBs if domain == AUTOSEL_DOM?
drivers/s390/crypto/zcrypt_api.c static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms, · line 1083
Quoted 2 lines
drivers/s390/crypto/zcrypt_api.c +1
-0if (ap_msg.flags &AP_MSG_FLAG_ADMIN ) { + domain =array_index_nospec (domain,AP_DOMAINS );
[Severity: High]
Does this use of array_index_nospec() map out-of-bounds domains to domain 0?
The guard condition for this block in _zcrypt_send_ep11_cprb() checks domain < AUTOSEL_DOM, but array_index_nospec() bounds against AP_DOMAINS.
If a user provides a domain value between AP_DOMAINS and AUTOSEL_DOM - 1, the array_index_nospec() call will forcefully mask the out-of-bounds domain to 0.
Will this result in checking perms->adm for domain 0 instead of the requested domain, potentially allowing an authorization bypass if the user has admin privileges for domain 0?
Quoted 3 lines
drivers/s390/crypto/zcrypt_api.c +0
-0if (!test_bit_inv (domain, perms->adm)) { rc = -ENODEV ; goto out;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Heiko Carstens
maintainerRe: [PATCH v2 1/1] s390/zcrypt: Close speculative mem read possibility
In reply to Harald FreudenbergerQuoted 14 lines · Harald Freudenberger
The domain value is extracted from a given CCA or EP11 ioctl struct when a CPRB is about to be sent. Thus this is a user controlled value. Under some special conditions (custom device node used, administrative load) this value is used as an array index after bounds checking, but without speculation barrier.
Add the missing
array_index_nospec()call to prevent speculative execution where this domain value is used.Fixes cfd68b33094e ("s390/zcrypt: Filter admin CPRBs on custom devices")Reported-by Christian Borntraeger <[email protected]>Signed-off-by Harald Freudenberger <[email protected]>Reviewed-by Finn Callies <[email protected]>
...
drivers/s390/crypto/zcrypt_api.c static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms, · line 1083
Quoted 5 lines
drivers/s390/crypto/zcrypt_api.c +1
-0@@ -1079,6 +1080,7 @@ static long _zcrypt_send_ep11_cprb(u32 xflags, struct ap_perms *perms,if (perms != &ap_perms && domain <AUTOSEL_DOM ) {if (ap_msg.flags &AP_MSG_FLAG_ADMIN ) { + domain =array_index_nospec (domain,AP_DOMAINS );
This hunk doesn't make sense, and it depends on the other patch you sent:
"s390/zcrypt: Fix wrong domain value verification with EP11 CPRBs". Please send them as a series of two.