From patchwork Tue Jul 2 09:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mishin X-Patchwork-Id: 13719324 X-Patchwork-Delegate: kuba@kernel.org Received: from mx1.t-argos.ru (mx1.t-argos.ru [109.73.34.58]) (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 0C1AA1534E1; Tue, 2 Jul 2024 09:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.73.34.58 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719913272; cv=none; b=QL/SuDVx8HJZyCr8tqgh5y2btlqzWkOLI00g7osd7vEPZ81Iudrsu24o35lUOt7VtxuR2AnlVRga0ehSxO00QhfXaUxqNCjaUIAyT3bm/6a98Yhdb3RJkF9PSwGzNctVuzxlz/uMl2QXWrVXx62/onxyPSd7tzJp8jYfycnsnPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719913272; c=relaxed/simple; bh=SSoKdTE7J3wyQ8wXdaVFr0+jrWF0Mqur4rJoN/pmTco=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=El0t4fdQOdU3YY7L0ShuuTKGkvFSIAU3TvWdSzZcfoPd2Pom2UffzBtNXuDY9tBTCMvjEji/XDZUppcrJ9htrGoAZHgHNJT+i5kFS2IsWA95Etiz8yfdnbNRln2QJYxXt2aTMn+2zIvKc2cSHeG0yn6B3ez2hZnUSN55QWpfvsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru; spf=pass smtp.mailfrom=t-argos.ru; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b=O9M0Mcsc; arc=none smtp.client-ip=109.73.34.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b="O9M0Mcsc" Received: from mx1.t-argos.ru (localhost [127.0.0.1]) by mx1.t-argos.ru (Postfix) with ESMTP id EAC85100003; Tue, 2 Jul 2024 12:40:37 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=t-argos.ru; s=mail; t=1719913238; bh=uMIWXotdz+X51cAHpgFbhL9+8Mu/Jf13+XYc0uWi5G0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=O9M0McscqZ+DMH80PvQAnDVwwBbzZziweWwYrhsuuDkTPK6WrwpxPkN4NHp0obRIa NekJj+wjrWynixaEcqB3R9wGZ7TFM8mQhZ7LWVNmQAA4kGGxC7yYg8p1g/+0AnNdI0 5rIO4ChcmQbbsAldsgWWGuMIjWKB+RJpDRHzyIo1OVE73gvewZrTmuQRMTQm88wqVr rFiifkrsuFdm0cu1wdppI3MiGX3eGZ1z7Qzea3+qx0yQ943+qntjuxGTmTldREHxq6 TYzc//O9Mi0SJU4rQ/GQAoAt3Qt1X2NN0rwG2gS0DEFlw5RaoZ94oIPFQzUySGroUk 4OBsfFbcbAVfQ== Received: from mx1.t-argos.ru.ru (ta-mail-02.ta.t-argos.ru [172.17.13.212]) by mx1.t-argos.ru (Postfix) with ESMTP; Tue, 2 Jul 2024 12:40:03 +0300 (MSK) Received: from localhost.localdomain (172.17.215.5) by ta-mail-02 (172.17.13.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 2 Jul 2024 12:39:43 +0300 From: Aleksandr Mishin To: Samuel Ortiz CC: Aleksandr Mishin , Krzysztof Kozlowski , , , Subject: [PATCH] nfc: pn533: Add poll mod list filling check Date: Tue, 2 Jul 2024 12:39:24 +0300 Message-ID: <20240702093924.12092-1-amishin@t-argos.ru> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: ta-mail-02.ta.t-argos.ru (172.17.13.212) To ta-mail-02 (172.17.13.212) X-KSMG-Rule-ID: 1 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 186273 [Jul 02 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: amishin@t-argos.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 21 0.3.21 ebee5449fc125b2da45f1a6a6bc2c5c0c3ad0e05, {Tracking_from_domain_doesnt_match_to}, 127.0.0.199:7.1.2;t-argos.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;mx1.t-argos.ru.ru:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2024/07/02 08:55:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2024/07/02 07:20:00 #25796017 X-KSMG-AntiVirus-Status: Clean, skipped X-Patchwork-Delegate: kuba@kernel.org 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. 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 --- 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 b19c39dcfbd9..e2bc67300a91 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));