From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C00F19A2A7; Thu, 6 Jun 2024 14:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683017; cv=none; b=l+Mi59nKZtPVyFrrQP5qgKej2yK5BtMCg2r1YlYcBBfXtEsnU/2iZbqSXbKHFXQzRe/fTXqxOPAPB3mZSHNVZjgJLAl1hAOV/rD5DWKW918u11o74DD7VjipveGs40B3JDBaUSGEdxLxrNYTnCDcdXFT5tPqFBKmPlBeMQWi37U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683017; c=relaxed/simple; bh=pJ68U0QzA32dquSG5yjgN3CDmdYLwLv+HVW8g74ESFg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MsBm1s185PGeNaUA3vF4rMRzof+6cs/dJ8gzgJu7ckRdUl2LQzYbZXoTYy9UTHCWhczZ7wL1lUOdV8C8U5aSRk09JLmvQMgQIAD9RgW0o2i6g1jCWF3BtQXbrqTWgKBeaWVME/N2v9xqtNjFLIbtvGddfcfQr+1+s/6YJhxRkJU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=C/xmSJ2/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="C/xmSJ2/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 543EEC32781; Thu, 6 Jun 2024 14:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683017; bh=pJ68U0QzA32dquSG5yjgN3CDmdYLwLv+HVW8g74ESFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C/xmSJ2/FMtjRtsCKYQrQw0XEuHoICyzo+fEkuXCCuAD5tgk8bzldPQR6sm2Ss6ft n6RjNjztH3pJTOUEeXLoIQDhx3eSZnnUm7m7NG59Q96hq+j/dqILUMsOKzz9pPTXdF +mzCrg8anbBndWPzEhL0jmrH9qwz6sjWIQPxXj7E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ryosuke Yasuoka , Krzysztof Kozlowski , "David S. Miller" , Sasha Levin , syzbot+d7b4dc6cd50410152534@syzkaller.appspotmail.com Subject: [PATCH 6.9 236/374] nfc: nci: Fix uninit-value in nci_rx_work Date: Thu, 6 Jun 2024 16:03:35 +0200 Message-ID: <20240606131659.724051466@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131651.683718371@linuxfoundation.org> References: <20240606131651.683718371@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ryosuke Yasuoka [ Upstream commit e4a87abf588536d1cdfb128595e6e680af5cf3ed ] syzbot reported the following uninit-value access issue [1] nci_rx_work() parses received packet from ndev->rx_q. It should be validated header size, payload size and total packet size before processing the packet. If an invalid packet is detected, it should be silently discarded. Fixes: d24b03535e5e ("nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet") Reported-and-tested-by: syzbot+d7b4dc6cd50410152534@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=d7b4dc6cd50410152534 [1] Signed-off-by: Ryosuke Yasuoka Reviewed-by: Krzysztof Kozlowski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/nfc/nci/core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index b133dc55304ce..7a9897fbf4f41 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -1463,6 +1463,19 @@ int nci_core_ntf_packet(struct nci_dev *ndev, __u16 opcode, ndev->ops->n_core_ops); } +static bool nci_valid_size(struct sk_buff *skb) +{ + BUILD_BUG_ON(NCI_CTRL_HDR_SIZE != NCI_DATA_HDR_SIZE); + unsigned int hdr_size = NCI_CTRL_HDR_SIZE; + + if (skb->len < hdr_size || + !nci_plen(skb->data) || + skb->len < hdr_size + nci_plen(skb->data)) { + return false; + } + return true; +} + /* ---- NCI TX Data worker thread ---- */ static void nci_tx_work(struct work_struct *work) @@ -1516,7 +1529,7 @@ static void nci_rx_work(struct work_struct *work) nfc_send_to_raw_sock(ndev->nfc_dev, skb, RAW_PAYLOAD_NCI, NFC_DIRECTION_RX); - if (!nci_plen(skb->data)) { + if (!nci_valid_size(skb)) { kfree_skb(skb); kcov_remote_stop(); break; -- 2.43.0