Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp832287ybl; Wed, 11 Dec 2019 08:10:31 -0800 (PST) X-Google-Smtp-Source: APXvYqzYM2hePqZUJCjIXDRiXnvrecuxR48UIwwcq5ic6hHny6c/d4wjj8G1d2UB5nZeLVsNPlzX X-Received: by 2002:a05:6808:197:: with SMTP id w23mr3560597oic.46.1576080630958; Wed, 11 Dec 2019 08:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080630; cv=none; d=google.com; s=arc-20160816; b=ULm0Aw/Box7vVOT/VESBEWtqc9if0XMlS+D2NCMPbGA+ytamQHOTEblbnYK4RUR+Ss ihmOwx24Xz0DsLZoFlALMlRjozzZ9Tf0owyQMH0PjipuzABLNb+nqW5bqdUPRNyIHgpX 0CF6nGAIEbmkMgUgxRmES0YCIhTJ+bujgqqZQ4v5L+jUSZDw5xZJHwIqdxYaxHedV+gO qRFxlN1Dr1moqb3tZP8FTd6g5s86frQX1HelBiPEuopx9jT4yKqoVt7qwColFoFeBHkk cUXM3j0WBaHkcj2e/2QdTJ3ZJ8rJmSqnbTW5s2XRmJhnjKcNAz0ggNU/rZCAH0TyrwSQ HjCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=l/m+NoLH63Bb9PV7rrJa8Ak15qoxk3patZdpl629Pr8=; b=LcgWxoqdgUL03r/flDemBBXS6h12Kt1X/Qrbu4cM1FUskCJKvOEvsJhYV7Z3JATzos dSPRwK+jQ5Osp9krSGY7igNrOHc78zleKqVwwFAq+xUWaTIxVhMv0i9CLcr/i+3cvnP/ E+bVP1s+jFNEpIlNQfrhsI0TfJNzXlGay86qVqMmhL/ruDBO3aBVsPk4jK1awnQOvSsg HDLGdxMh44UWsTUFDIhE4XcD4kMk3ZdP9/yF4dwbHc49wMoau6RSTe0+5bsv4j3NilSs 79lk1OPjb/pExklhQ0wKyid94SX618IUm2bmt6aTgRkdIdaV+NaD7sDeBtDl2XmXVYwe OX7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=woLE8CYu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si1394897otk.88.2019.12.11.08.10.17; Wed, 11 Dec 2019 08:10:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=woLE8CYu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731067AbfLKPMM (ORCPT + 99 others); Wed, 11 Dec 2019 10:12:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:32806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731028AbfLKPMB (ORCPT ); Wed, 11 Dec 2019 10:12:01 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA36F24682; Wed, 11 Dec 2019 15:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077121; bh=VuytPSLb+8F9+jtnOgEB06wArOxY6MKT/sSY+vsFQLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=woLE8CYuVpCYwjYWJyZR27S1ED/xkHi1eZc8RUJkvc2fiyUL8OiQgtMs0oEy/1P+k wO4LwJOkgYztFHKBtmRiLsprKlSt44sjQ7kSf0E60MVVhtztUnfvF/NUdPEVUIfDMM KakSyxsRKchfU3k2CBdfcqG4oVRiqGeG1qi7vO30= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Andy Shevchenko , "David S. Miller" , Sasha Levin Subject: [PATCH 5.3 025/105] NFC: nxp-nci: Fix NULL pointer dereference after I2C communication error Date: Wed, 11 Dec 2019 16:05:14 +0100 Message-Id: <20191211150229.013991971@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephan Gerhold [ Upstream commit a71a29f50de1ef97ab55c151a1598eb12dde379d ] 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: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver") Signed-off-by: Stephan Gerhold Reviewed-by: Andy Shevchenko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/nfc/nxp-nci/i2c.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 4aeb3861b4095..6c468899f2ffe 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -225,8 +225,10 @@ static irqreturn_t nxp_nci_i2c_irq_thread_fn(int irq, void *phy_id) if (r == -EREMOTEIO) { phy->hard_fault = r; - skb = NULL; - } else if (r < 0) { + if (info->mode == NXP_NCI_MODE_FW) + nxp_nci_fw_recv_frame(phy->ndev, NULL); + } + if (r < 0) { nfc_err(&client->dev, "Read failed with error %d\n", r); goto exit_irq_handled; } -- 2.20.1