diff mbox series

[1/2] tpci: fix NULL pointer dereference on wrong test invocation

Message ID 20210618130536.54806-1-krzysztof.kozlowski@canonical.com
State Accepted
Headers show
Series [1/2] tpci: fix NULL pointer dereference on wrong test invocation | expand

Commit Message

Krzysztof Kozlowski June 18, 2021, 1:05 p.m. UTC
Fix NULL pointer dereference when a ltp_tpci test case is started before
choosing the device:

    ltp_tpci: test-case 12
    ltp_tpci: assign resources
    ltp_tpci: assign resource #0
    BUG: kernel NULL pointer dereference, address: 00000000000003b8
    ...
     Call Trace:
      dev_attr_store+0x17/0x30
      sysfs_kf_write+0x3e/0x50
      kernfs_fop_write_iter+0x13c/0x1d0
      new_sync_write+0x113/0x1a0
      vfs_write+0x1c5/0x200
      ksys_write+0x67/0xe0
      __x64_sys_write+0x1a/0x20
      do_syscall_64+0x49/0xc0
      entry_SYSCALL_64_after_hwframe+0x44/0xa9

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Krzysztof Kozlowski June 24, 2021, 7:32 p.m. UTC | #1
On 18/06/2021 15:05, Krzysztof Kozlowski wrote:
> Fix NULL pointer dereference when a ltp_tpci test case is started before
> choosing the device:
> 
>     ltp_tpci: test-case 12
>     ltp_tpci: assign resources
>     ltp_tpci: assign resource #0
>     BUG: kernel NULL pointer dereference, address: 00000000000003b8
>     ...
>      Call Trace:
>       dev_attr_store+0x17/0x30
>       sysfs_kf_write+0x3e/0x50
>       kernfs_fop_write_iter+0x13c/0x1d0
>       new_sync_write+0x113/0x1a0
>       vfs_write+0x1c5/0x200
>       ksys_write+0x67/0xe0
>       __x64_sys_write+0x1a/0x20
>       do_syscall_64+0x49/0xc0
>       entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> ---
>  testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 

Hi everyone,

Any comments on these two tpci patches? Do they look reasonable?

Best regards,
Krzysztof
Petr Vorel June 28, 2021, 8 p.m. UTC | #2
Hi Krzysztof,

> On 18/06/2021 15:05, Krzysztof Kozlowski wrote:
> > Fix NULL pointer dereference when a ltp_tpci test case is started before
> > choosing the device:

> >     ltp_tpci: test-case 12
> >     ltp_tpci: assign resources
> >     ltp_tpci: assign resource #0
> >     BUG: kernel NULL pointer dereference, address: 00000000000003b8
> >     ...
> >      Call Trace:
> >       dev_attr_store+0x17/0x30
> >       sysfs_kf_write+0x3e/0x50
> >       kernfs_fop_write_iter+0x13c/0x1d0
> >       new_sync_write+0x113/0x1a0
> >       vfs_write+0x1c5/0x200
> >       ksys_write+0x67/0xe0
> >       __x64_sys_write+0x1a/0x20
> >       do_syscall_64+0x49/0xc0
> >       entry_SYSCALL_64_after_hwframe+0x44/0xa9

Merged this one, thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
index 5b48aa0c7ece..f2d4a4ba497c 100644
--- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
+++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
@@ -556,6 +556,11 @@  static int test_case(unsigned int cmd)
 {
 	int rc = TSKIP;
 
+	if (!ltp_pci.dev || !ltp_pci.bus) {
+		prk_err("device or bus not selected for test");
+		return TFAIL;
+	}
+
 	switch (cmd) {
 	case PCI_ENABLE:
 		rc = pci_enable();