linux-stable/drivers/nfc
Stephan Gerhold 7a9b522fa6 NFC: nxp-nci: Fix NULL pointer dereference after I2C communication error
[ Upstream commit a71a29f50d ]

I2C communication errors (-EREMOTEIO) during the IRQ handler of nxp-nci
result in a NULL pointer dereference at the moment:

    BUG: kernel NULL pointer dereference, address: 0000000000000000
    Oops: 0002 [#1] PREEMPT SMP NOPTI
    CPU: 1 PID: 355 Comm: irq/137-nxp-nci Not tainted 5.4.0-rc6 #1
    RIP: 0010:skb_queue_tail+0x25/0x50
    Call Trace:
     nci_recv_frame+0x36/0x90 [nci]
     nxp_nci_i2c_irq_thread_fn+0xd1/0x285 [nxp_nci_i2c]
     ? preempt_count_add+0x68/0xa0
     ? irq_forced_thread_fn+0x80/0x80
     irq_thread_fn+0x20/0x60
     irq_thread+0xee/0x180
     ? wake_threads_waitq+0x30/0x30
     kthread+0xfb/0x130
     ? irq_thread_check_affinity+0xd0/0xd0
     ? kthread_park+0x90/0x90
     ret_from_fork+0x1f/0x40

Afterward the kernel must be rebooted to work properly again.

This happens because it attempts to call nci_recv_frame() with skb == NULL.
However, unlike nxp_nci_fw_recv_frame(), nci_recv_frame() does not have any
NULL checks for skb, causing the NULL pointer dereference.

Change the code to call only nxp_nci_fw_recv_frame() in case of an error.
Make sure to log it so it is obvious that a communication error occurred.
The error above then becomes:

    nxp-nci_i2c i2c-NXP1001:00: NFC: Read failed with error -121
    nci: __nci_request: wait_for_completion_interruptible_timeout failed 0
    nxp-nci_i2c i2c-NXP1001:00: NFC: Read failed with error -121

Fixes: 6be88670fc ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-12-17 20:37:27 +01:00
..
fdp NFC: fdp: fix incorrect free object 2019-11-12 19:17:53 +01:00
microread License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nfcmrvl NFC: nfcmrvl: fix gpio-handling regression 2019-08-09 17:53:35 +02:00
nxp-nci NFC: nxp-nci: Fix NULL pointer dereference after I2C communication error 2019-12-17 20:37:27 +01:00
pn533 NFC: pn533: fix use-after-free and memleaks 2019-11-06 12:43:37 +01:00
pn544 NFC: pn544: Switch to devm_acpi_dev_add_driver_gpios() 2017-06-22 23:51:44 +02:00
s3fwrn5
st-nci st_nci_hci_connectivity_event_received: null check the allocation 2019-08-29 08:26:38 +02:00
st21nfca NFC: st21nfca: fix double free 2019-11-12 19:17:55 +01:00
st95hf spi: ST ST95HF NFC: declare missing of table 2019-05-16 19:42:24 +02:00
Kconfig NFC: trf7970a: Convert to descriptor based GPIO interface 2017-06-18 23:57:58 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mei_phy.c
mei_phy.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nfcsim.c NFC: add NULL checks to avoid potential NULL pointer dereference 2017-06-23 00:34:56 +02:00
port100.c nfc: port100: handle command failure cleanly 2019-12-01 09:14:23 +01:00
trf7970a.c NFC: trf7970a: Correct register settings for 27MHz clock 2017-06-28 09:16:54 +02:00