From patchwork Wed Sep 6 23:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Cline X-Patchwork-Id: 13375965 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 C836D11CBE for ; Wed, 6 Sep 2023 23:34:08 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC1EE66; Wed, 6 Sep 2023 16:34:06 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 916C65C00E3; Wed, 6 Sep 2023 19:34:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 06 Sep 2023 19:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jcline.org; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to; s=fm1; t=1694043243; x=1694129643; bh=vBTjdMfz1C O5+QvldXBB+2bQ59B3jeU81T91GJRZKcc=; b=lCbZbYYS3BAZ5uNKthMk1f2xTa Fai2IZ8aUGUTKsBa07bR8OklHlqG2i35GZqaBndYGzq2G+s6q+wh3gpiypHMHkv0 VgUeQbWrCOuMtmTlFY+iWtQhvgGiwunlAghInQvPUhsdvRQkEtCVsU+dw/9oieLG DcmrWC7/mZ3exbfVNeXuPpO9FoLprv+YZTmtxWll8OTgpdUBMEPNXrWjLRtwYWot dGnDJibx0k/kIXpr5WDpT37RWKJGjQg1ciEiTB19qgb8lqRMstyk2xgz7FHODibE eq9X79czzYlxXsF7+WMVQbdS9i/SuC8TDgOC5qYNahPRBugZr8WP7uUGvgJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1694043243; x=1694129643; bh=vBTjdMfz1CO5+ QvldXBB+2bQ59B3jeU81T91GJRZKcc=; b=gJHjU750+HzSv7RYPPkd3G/rLMEs+ obWwwh3TAzL5rtFQUCV16ciho2lwUcRbnM8Kf20i+iX4PPyN/AI9exx7FKFV5Wxe 1O5I9QMItyY4P4L88Pz5ndQ8iojAMB0PpD3ugJDL4iFVTxeWFk7Shd88cND8j9SA 5qWHdHVeGUK9kIIvUxxuDWRbyJhqASjjvcIOF7ieJSY1rJKS05O3LUFJ9AB0KSDE k+nEwnR4zJAiyeslbr5OkrHZflH91oTKfp54dv+wEnBBhy4ZL1Zv7ity0qhjZNZg RvvDAxP4hBcmA98u70lmdCYzEFjN6PU6NEgiIIYawfUImSYTzbJ2mmbCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomheplfgvrhgvmhih ucevlhhinhgvuceojhgvrhgvmhihsehjtghlihhnvgdrohhrgheqnecuggftrfgrthhtvg hrnhepveelveefheeuhffhieduvefgudefiedvfeduteejlefflefggfekvdeuhffgteev necuffhomhgrihhnpehshiiikhgrlhhlvghrrdgrphhpshhpohhtrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhgvrhgvmhihsehj tghlihhnvgdrohhrgh X-ME-Proxy: Feedback-ID: i7a7146c5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Sep 2023 19:34:02 -0400 (EDT) From: Jeremy Cline To: Krzysztof Kozlowski Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Cline , syzbot+0839b78e119aae1fec78@syzkaller.appspotmail.com Subject: [PATCH] nfc: nci: assert requested protocol is valid Date: Wed, 6 Sep 2023 19:33:47 -0400 Message-ID: <20230906233347.823171-1-jeremy@jcline.org> X-Mailer: git-send-email 2.41.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The protocol is used in a bit mask to determine if the protocol is supported. Assert the provided protocol is less than the maximum defined so it doesn't potentially perform a shift-out-of-bounds and provide a clearer error for undefined protocols vs unsupported ones. Fixes: 6a2968aaf50c ("NFC: basic NCI protocol implementation") Reported-and-tested-by: syzbot+0839b78e119aae1fec78@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=0839b78e119aae1fec78 Signed-off-by: Jeremy Cline Reviewed-by: Simon Horman --- net/nfc/nci/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index fff755dde30d..6c9592d05120 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -909,6 +909,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, return -EINVAL; } + if (protocol >= NFC_PROTO_MAX) { + pr_err("the requested nfc protocol is invalid\n"); + return -EINVAL; + } + if (!(nci_target->supported_protocols & (1 << protocol))) { pr_err("target does not support the requested protocol 0x%x\n", protocol);