Skip to contentSkip to conversation

crypto: atmel-sha204a - Fix uninitialized data access on OTP read error

PATCH In review Thorsten Blum 3 participants 4 messages Feb 20 – Mar 7

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: atmel-sha204a - Fix uninitialized data access on OTP read error

Return early if atmel_i2c_send_receive() fails to avoid checking potentially uninitialized data in 'cmd.data'.

Fixes e05ce444e9e5 ("crypto: atmel-sha204a - add reading from otp zone")
---
 drivers/crypto/atmel-sha204a.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/atmel-sha204a.c +4 -0
index 0fcf4a39de27..f4a04b297257 100644
@@ -103,6 +103,10 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
 	}
 
 	ret = atmel_i2c_send_receive(client, &cmd);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to read otp at %04X\n", addr);
+		return ret;
+	}
 
 	if (cmd.data[0] == 0xff) {
 		dev_err(&client->dev, "failed, device not ready\n");
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#1 lore raw

Hi Thorsten! So this one was tested on your hardware?

Wouldn't it make more sense to squash this with the patch before: 'Fix error codes in OTP reads' (which IMHO actually fixes mainly the bounds check)? This on it's own I'd consider rather a refac than "Fixes".

Quoted 30 lines · Thorsten Blum

Return early if atmel_i2c_send_receive() fails to avoid checking potentially uninitialized data in 'cmd.data'.

Fixes e05ce444e9e5 ("crypto: atmel-sha204a - add reading from otp zone")
---
 drivers/crypto/atmel-sha204a.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/atmel-sha204a.c +4 -1
index 0fcf4a39de27..f4a04b297257 100644
@@ -103,6 +103,10 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
        }
 
        ret = atmel_i2c_send_receive(client, &cmd);
+       if (ret < 0) {
+               dev_err(&client->dev, "failed to read otp at %04X\n", addr);
+               return ret;
+       }
 
        if (cmd.data[0] == 0xff) {
                dev_err(&client->dev, "failed, device not ready\n");
--

Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4

#2 lore raw
Quoted 5 lines · Lothar Rubusch

Hi Thorsten! So this one was tested on your hardware?

Wouldn't it make more sense to squash this with the patch before: 'Fix error codes in OTP reads' (which IMHO actually fixes mainly the bounds check)? This on it's own I'd consider rather a refac than "Fixes".

Sorry, I forgot to add that I only compile-tested it (like the others), as I don't have access to the hardware right now. If you could test it on your setup, that would be very much appreciated.

And yes, happy to squash them, I just found it after submitting [1].

Thanks,
Thorsten

[1] https://lore.kernel.org/lkml/[email protected]/

maintainer
#3 lore raw
In reply to Thorsten Blum
Quoted 9 lines · Thorsten Blum

Return early if atmel_i2c_send_receive() fails to avoid checking potentially uninitialized data in 'cmd.data'.

Fixes e05ce444e9e5 ("crypto: atmel-sha204a - add reading from otp zone")
---
 drivers/crypto/atmel-sha204a.c | 4 ++++
 1 file changed, 4 insertions(+)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt