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 362941C7D76; Thu, 6 Jun 2024 14:21:48 +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=1717683708; cv=none; b=rGtX8MGB134Hyf8xSqk+3ZyIbU0wFkE3NC+IvMiZGRMlPtnzpABqNKZPVqs1RnYEke8Gdl832IHPS2AHxXorWwXjKXtkePbuj5q+jYMjphzRDjWRDmzO+gOSJwSLKkoRK4OulqkMO/pjbi7QOOEdPzpDazy6idBfWLG2/+O+Ymk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683708; c=relaxed/simple; bh=WPnsqHKzpuMjHZ/GreK6L8KoLHJncOK0vIKFbbddWiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NkrRjOMk9GT/LCG7wK6yTRxV/+JSJ2SbtDERYEXsWlv5WZPOdSoLb5e8q5yU8BRoNJi87tzhCeXpOGgfrRegdeRkOQtsbEiC4A0l+6xTnbOLH27nDRrKRMzq8Xxc5p3yHW4W8bO9cUdQIOHC/SPBrW4sjknBc9PbbfowGSBXinY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lB2QqmGj; 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="lB2QqmGj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A97AC2BD10; Thu, 6 Jun 2024 14:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683708; bh=WPnsqHKzpuMjHZ/GreK6L8KoLHJncOK0vIKFbbddWiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lB2QqmGjKlieUsrtsXyBMsHsqILemRs8Brr1sFTQb9yNpBkpbhKljHdRf8h/BR+Bj WvLnMs6baXXS4mvb1Fq6ap8UrGlFijbFyn9rYHESqreSv9qKzGQ1kZSpiMjhcSk0uh 3XJZDSPzvGPF6wN/19Z1HXMJM4JnX9cAFVq4lfds= 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.6 636/744] nfc: nci: Fix uninit-value in nci_rx_work Date: Thu, 6 Jun 2024 16:05:08 +0200 Message-ID: <20240606131752.880603680@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131732.440653204@linuxfoundation.org> References: <20240606131732.440653204@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.6-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 5d708af0fcfd3..f350c5fb992ec 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