2024-03-01 14:37:54

by Sumit Garg

[permalink] [raw]
Subject: [PATCH] tee: optee: Fix kernel panic caused by incorrect error handling

The error path while failing to register devices on the TEE bus has a
bug leading to kernel panic as follows:

[ 15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
[ 15.406913] Mem abort info:
[ 15.409722] ESR = 0x0000000096000005
[ 15.413490] EC = 0x25: DABT (current EL), IL = 32 bits
[ 15.418814] SET = 0, FnV = 0
[ 15.421878] EA = 0, S1PTW = 0
[ 15.425031] FSC = 0x05: level 1 translation fault
[ 15.429922] Data abort info:
[ 15.432813] ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
[ 15.438310] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[ 15.443372] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[ 15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
[ 15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
[ 15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP

Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
lead to the introduction of this bug. So fix it appropriately.

Reported-by: Mikko Rapeli <[email protected]>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
Cc: [email protected]
Signed-off-by: Sumit Garg <[email protected]>
---
drivers/tee/optee/device.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
index 9d2afac96acc..d296c70ddfdc 100644
--- a/drivers/tee/optee/device.c
+++ b/drivers/tee/optee/device.c
@@ -90,13 +90,14 @@ static int optee_register_device(const uuid_t *device_uuid, u32 func)
if (rc) {
pr_err("device registration failed, err: %d\n", rc);
put_device(&optee_device->dev);
+ return rc;
}

if (func == PTA_CMD_GET_DEVICES_SUPP)
device_create_file(&optee_device->dev,
&dev_attr_need_supplicant);

- return rc;
+ return 0;
}

static int __optee_enumerate_devices(u32 func)
--
2.34.1



2024-03-04 05:45:33

by Sumit Garg

[permalink] [raw]
Subject: Re: [PATCH] tee: optee: Fix kernel panic caused by incorrect error handling

+ Arnd

On Fri, 1 Mar 2024 at 20:07, Sumit Garg <[email protected]> wrote:
>
> The error path while failing to register devices on the TEE bus has a
> bug leading to kernel panic as follows:
>
> [ 15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
> [ 15.406913] Mem abort info:
> [ 15.409722] ESR = 0x0000000096000005
> [ 15.413490] EC = 0x25: DABT (current EL), IL = 32 bits
> [ 15.418814] SET = 0, FnV = 0
> [ 15.421878] EA = 0, S1PTW = 0
> [ 15.425031] FSC = 0x05: level 1 translation fault
> [ 15.429922] Data abort info:
> [ 15.432813] ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
> [ 15.438310] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
> [ 15.443372] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
> [ 15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
> [ 15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
> [ 15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
>
> Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> lead to the introduction of this bug. So fix it appropriately.
>
> Reported-by: Mikko Rapeli <[email protected]>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
> Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> Cc: [email protected]
> Signed-off-by: Sumit Garg <[email protected]>
> ---
> drivers/tee/optee/device.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>

Jens, Arnd,

Is there any chance for this fix to make it into v6.8 release?

-Sumit

> diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
> index 9d2afac96acc..d296c70ddfdc 100644
> --- a/drivers/tee/optee/device.c
> +++ b/drivers/tee/optee/device.c
> @@ -90,13 +90,14 @@ static int optee_register_device(const uuid_t *device_uuid, u32 func)
> if (rc) {
> pr_err("device registration failed, err: %d\n", rc);
> put_device(&optee_device->dev);
> + return rc;
> }
>
> if (func == PTA_CMD_GET_DEVICES_SUPP)
> device_create_file(&optee_device->dev,
> &dev_attr_need_supplicant);
>
> - return rc;
> + return 0;
> }
>
> static int __optee_enumerate_devices(u32 func)
> --
> 2.34.1
>

2024-03-04 13:30:37

by Jens Wiklander

[permalink] [raw]
Subject: Re: [PATCH] tee: optee: Fix kernel panic caused by incorrect error handling

Hi,

On Mon, Mar 4, 2024 at 6:45 AM Sumit Garg <[email protected]> wrote:
>
> + Arnd
>
> On Fri, 1 Mar 2024 at 20:07, Sumit Garg <[email protected]> wrote:
> >
> > The error path while failing to register devices on the TEE bus has a
> > bug leading to kernel panic as follows:
> >
> > [ 15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
> > [ 15.406913] Mem abort info:
> > [ 15.409722] ESR = 0x0000000096000005
> > [ 15.413490] EC = 0x25: DABT (current EL), IL = 32 bits
> > [ 15.418814] SET = 0, FnV = 0
> > [ 15.421878] EA = 0, S1PTW = 0
> > [ 15.425031] FSC = 0x05: level 1 translation fault
> > [ 15.429922] Data abort info:
> > [ 15.432813] ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
> > [ 15.438310] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
> > [ 15.443372] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
> > [ 15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
> > [ 15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
> > [ 15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
> >
> > Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> > lead to the introduction of this bug. So fix it appropriately.
> >
> > Reported-by: Mikko Rapeli <[email protected]>
> > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
> > Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> > Cc: [email protected]
> > Signed-off-by: Sumit Garg <[email protected]>
> > ---
> > drivers/tee/optee/device.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
>
> Jens, Arnd,
>
> Is there any chance for this fix to make it into v6.8 release?

I'm picking up this and have also just sent it in a pull request for
v6.8. If it makes it into v6.8 remains to be seen.

Thanks,
Jens

>
> -Sumit
>
> > diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
> > index 9d2afac96acc..d296c70ddfdc 100644
> > --- a/drivers/tee/optee/device.c
> > +++ b/drivers/tee/optee/device.c
> > @@ -90,13 +90,14 @@ static int optee_register_device(const uuid_t *device_uuid, u32 func)
> > if (rc) {
> > pr_err("device registration failed, err: %d\n", rc);
> > put_device(&optee_device->dev);
> > + return rc;
> > }
> >
> > if (func == PTA_CMD_GET_DEVICES_SUPP)
> > device_create_file(&optee_device->dev,
> > &dev_attr_need_supplicant);
> >
> > - return rc;
> > + return 0;
> > }
> >
> > static int __optee_enumerate_devices(u32 func)
> > --
> > 2.34.1
> >

2024-03-04 17:05:56

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH] tee: optee: Fix kernel panic caused by incorrect error handling

On Mon, Mar 4, 2024, at 06:45, Sumit Garg wrote:
> + Arnd
>
> On Fri, 1 Mar 2024 at 20:07, Sumit Garg <[email protected]> wrote:
>>
>> The error path while failing to register devices on the TEE bus has a
>> bug leading to kernel panic as follows:
>>
>> [ 15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
>> [ 15.406913] Mem abort info:
>> [ 15.409722] ESR = 0x0000000096000005
>> [ 15.413490] EC = 0x25: DABT (current EL), IL = 32 bits
>> [ 15.418814] SET = 0, FnV = 0
>> [ 15.421878] EA = 0, S1PTW = 0
>> [ 15.425031] FSC = 0x05: level 1 translation fault
>> [ 15.429922] Data abort info:
>> [ 15.432813] ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
>> [ 15.438310] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
>> [ 15.443372] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
>> [ 15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
>> [ 15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
>> [ 15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
>>
>> Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
>> lead to the introduction of this bug. So fix it appropriately.
>>
>> Reported-by: Mikko Rapeli <[email protected]>
>> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
>> Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
>> Cc: [email protected]
>> Signed-off-by: Sumit Garg <[email protected]>
>> ---
>> drivers/tee/optee/device.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>
> Jens, Arnd,
>
> Is there any chance for this fix to make it into v6.8 release?

I merged the pull request into my arm/fixes branch now, will
send the branch on once it passes CI.

Arnd

2024-03-05 05:34:41

by Sumit Garg

[permalink] [raw]
Subject: Re: [PATCH] tee: optee: Fix kernel panic caused by incorrect error handling

On Mon, 4 Mar 2024 at 22:35, Arnd Bergmann <[email protected]> wrote:
>
> On Mon, Mar 4, 2024, at 06:45, Sumit Garg wrote:
> > + Arnd
> >
> > On Fri, 1 Mar 2024 at 20:07, Sumit Garg <[email protected]> wrote:
> >>
> >> The error path while failing to register devices on the TEE bus has a
> >> bug leading to kernel panic as follows:
> >>
> >> [ 15.398930] Unable to handle kernel paging request at virtual address ffff07ed00626d7c
> >> [ 15.406913] Mem abort info:
> >> [ 15.409722] ESR = 0x0000000096000005
> >> [ 15.413490] EC = 0x25: DABT (current EL), IL = 32 bits
> >> [ 15.418814] SET = 0, FnV = 0
> >> [ 15.421878] EA = 0, S1PTW = 0
> >> [ 15.425031] FSC = 0x05: level 1 translation fault
> >> [ 15.429922] Data abort info:
> >> [ 15.432813] ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
> >> [ 15.438310] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
> >> [ 15.443372] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
> >> [ 15.448697] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000d9e3e000
> >> [ 15.455413] [ffff07ed00626d7c] pgd=1800000bffdf9003, p4d=1800000bffdf9003, pud=0000000000000000
> >> [ 15.464146] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
> >>
> >> Commit 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> >> lead to the introduction of this bug. So fix it appropriately.
> >>
> >> Reported-by: Mikko Rapeli <[email protected]>
> >> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218542
> >> Fixes: 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration")
> >> Cc: [email protected]
> >> Signed-off-by: Sumit Garg <[email protected]>
> >> ---
> >> drivers/tee/optee/device.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >
> > Jens, Arnd,
> >
> > Is there any chance for this fix to make it into v6.8 release?
>
> I merged the pull request into my arm/fixes branch now, will
> send the branch on once it passes CI.

Thanks.

-Sumit

>
> Arnd