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 4184C1DFD1; Sun, 1 Sep 2024 16:48:53 +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=1725209333; cv=none; b=gR5rMw/OLrndUfypvREy6eDMCMVWGHrAhvWgmvt48caFTH8rB+9Vvjw+qq1UJt+K2+vNFVHVS44Dsg+qxqJpgMl3Rwky8whb1996DpKOPyKMmzBWT7TfXhJI7C2bJkK6NAtWqO8TjXUL/fe/JQvwgBnWHFx9paW9N1gW0+RG/Rg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725209333; c=relaxed/simple; bh=2UJqfxfErCD5IBg93bNQ6JQmJt0VUnL/4/tkjmzU6mk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c7LaTA9EQYh2FLy4G3AHdXqEIDZ4FS6wsXNgbW54AsrMJRb6axYCnBgAy6rYEeZiEgRnx9tBIJSQntqUBqKrgcsNYwzwp/G4pKx/lMx3ho/UzfhwzQCzBJ/vgIu8QbYgTmS4YS/ROuL4CA9wEdYirkOKEbFdOyAlIXovRogMn/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L4wt9f62; 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="L4wt9f62" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBB8EC4CEC3; Sun, 1 Sep 2024 16:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725209333; bh=2UJqfxfErCD5IBg93bNQ6JQmJt0VUnL/4/tkjmzU6mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L4wt9f62pVE83Q56txTM3I1LcsUlzU870mYZeGaAaKYp/Kq5V2QthNUtxldG9YzKE d7O7ht7LmLtiwGUwkDvo+fqrYqDVlFMgLCPLdw4CBbZ3/s2vZDZDfc3VS4t28NIpaB zrygs4m4u4JkiHsFfTcXrNs36q+u3PSs80qmJnf0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Aleksandr Mishin , Krzysztof Kozlowski , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 55/71] nfc: pn533: Add poll mod list filling check Date: Sun, 1 Sep 2024 18:18:00 +0200 Message-ID: <20240901160803.965128423@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240901160801.879647959@linuxfoundation.org> References: <20240901160801.879647959@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aleksandr Mishin [ Upstream commit febccb39255f9df35527b88c953b2e0deae50e53 ] In case of im_protocols value is 1 and tm_protocols value is 0 this combination successfully passes the check 'if (!im_protocols && !tm_protocols)' in the nfc_start_poll(). But then after pn533_poll_create_mod_list() call in pn533_start_poll() poll mod list will remain empty and dev->poll_mod_count will remain 0 which lead to division by zero. Normally no im protocol has value 1 in the mask, so this combination is not expected by driver. But these protocol values actually come from userspace via Netlink interface (NFC_CMD_START_POLL operation). So a broken or malicious program may pass a message containing a "bad" combination of protocol parameter values so that dev->poll_mod_count is not incremented inside pn533_poll_create_mod_list(), thus leading to division by zero. Call trace looks like: nfc_genl_start_poll() nfc_start_poll() ->start_poll() pn533_start_poll() Add poll mod list filling check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: dfccd0f58044 ("NFC: pn533: Add some polling entropy") Signed-off-by: Aleksandr Mishin Acked-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20240827084822.18785-1-amishin@t-argos.ru Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/nfc/pn533/pn533.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c index f0cac19005527..2e0871409926b 100644 --- a/drivers/nfc/pn533/pn533.c +++ b/drivers/nfc/pn533/pn533.c @@ -1723,6 +1723,11 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, } pn533_poll_create_mod_list(dev, im_protocols, tm_protocols); + if (!dev->poll_mod_count) { + nfc_err(dev->dev, + "Poll mod list is empty\n"); + return -EINVAL; + } /* Do not always start polling from the same modulation */ get_random_bytes(&rand_mod, sizeof(rand_mod)); -- 2.43.0