From patchwork Wed Apr 18 10:05:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 133610 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5694505ljb; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx488tkhk7kE0bv31zBUO5ZQkwsLUXW1trJBLkxZFTYprVMZCL7T+KkXTqhJvumcucHlUrZGF X-Received: by 2002:a17:902:9042:: with SMTP id w2-v6mr1488767plz.34.1524045929523; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524045929; cv=none; d=google.com; s=arc-20160816; b=g84g8KsH95+6WT1xbHRDNaZimRgzIDNUXCmzoSc/KxRSb0jQZuXpi1DUr9+pcbw3ao qdmzurHi3ia1eoSpNfmeOvAKY+rEPvgdtJl4pfouXZrk24xVrAgAxGwTZanbIr5DOT3r Q1GOs8dbdvdylqfBLud9lGKRfEDNUTS3lzoi5Q1WKoXdlwEcI29s+spAfvRHVsK4/Eko UNnXvjPzKO+kcQrGOB2DOyzD3Mfzoqg/JQKFqzdd+K6uNQeUUIJMvyRqbnwSJSbyvjkK HaNE3VlC9x5tKbLaRDDVUOFMdCaZzMH8+c4xab0WpBuLLp8AT9y7F+keqYZAybHDg+2u li6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=nw3CukL03REDLvgiZ7T+CVEV0s01xjA3eSxqq0B+22RwT68OXXmRz8kyJw8GWBZ+SY Q84jLjCiLQWlJuMxMJ7GGY2R3HQB4Jd7u4FiVTOEvK6zlZljyyEFv5CiCm4b1WTLhQW5 VRgvnRt0B+0W0t+/orreSwXzo45qjGQtT74/gIoLNorjGky/lBRDSmJvC2JIOLZwT886 TIHiMYnANsEn9GBWXgikqnRkA0zuF3nbhZvTPkun5hk8i6zeN4E6Iiu1vNVISfLqMwt1 8ds2kC0vIFmJIs2RzvXrmfWrDfB9uq4b2WGAbsqiVqufsh7ssilt1nq1madI1qn8QBrb ZRCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgoKY9QP; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10-v6si1034543pln.257.2018.04.18.03.05.29; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgoKY9QP; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753211AbeDRKFZ (ORCPT + 3 others); Wed, 18 Apr 2018 06:05:25 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37453 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbeDRKFX (ORCPT ); Wed, 18 Apr 2018 06:05:23 -0400 Received: by mail-pl0-f67.google.com with SMTP id f7-v6so828221plr.4 for ; Wed, 18 Apr 2018 03:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=dgoKY9QPAfnZ6d8CarORSyA0bspt8j2khoUsx2GlxY0f5Ex8/4AAUrz4qmnZEw9Bi9 alWKLWv6Y/rSh0wz8ivjDlrV+r/iMq3TN2A5pehooMZ4z7bqxTwWJiPlN70P+eeqj8Oa L6+X9wRrY9NOpIsWT38TsX/TEPaTbJ8sQ3N1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=XMUdg7pml2DlEjdmqT4MYwp4T+zvqAvp2+P42biNy5y741NqILg2ZWdaiZFs5qn6nU pOSVEtfhWilFTpVh0srhM9SEZ1ksvgIwcn70w6kVXpKCKk+1OPL0KAFrfUsFvMfGWCDc lkeGizIQA6jrHDycQ9Snuck0EQ7hxjYXJ04ykiwlzpO4HewCdJpTapE11SDQyyjnAPJ7 iZWNxQmso7ZI7GDGmHIk6R17zcUdu5j/FkwzwyUSXnf+vJmFHIDY9qqYEXaAM9OxVnkO t0taqpmUDRYHF1lV7dxltDPa6lAQ54CfKHd7eytOlpTa/GnrnWf3XQ5UHvUeG03pIWNg YhWQ== X-Gm-Message-State: ALQs6tCg7/+ITFktGRlEoqxOej0MOpBbgibKbN2eT5aIdvUBJ7zG8jc1 p6BrK9Iu86JHggjk0Kr1BR+FFQ== X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr1487334pla.345.1524045923344; Wed, 18 Apr 2018 03:05:23 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:22 -0700 (PDT) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Samuel Ortiz , Christophe Ricard , Andy Shevchenko , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team , Suren Baghdasaryan Subject: [RESEND][PATCH 3/4] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Wed, 18 Apr 2018 15:35:03 +0530 Message-Id: <1524045904-7005-4-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524045904-7005-1-git-send-email-amit.pundir@linaro.org> References: <1524045904-7005-1-git-send-email-amit.pundir@linaro.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Suren Baghdasaryan When handling SHDLC I-Frame commands "pipe" field used for indexing into an array should be checked before usage. If left unchecked it might access memory outside of the array of size NFC_HCI_MAX_PIPES(127). Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- net/nfc/hci/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.7.4 diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c index ac8030c4bcf8..19cb2e473ea6 100644 --- a/net/nfc/hci/core.c +++ b/net/nfc/hci/core.c @@ -209,6 +209,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd, } create_info = (struct hci_create_pipe_resp *)skb->data; + if (create_info->pipe >= NFC_HCI_MAX_PIPES) { + status = NFC_HCI_ANY_E_NOK; + goto exit; + } + /* Save the new created pipe and bind with local gate, * the description for skb->data[3] is destination gate id * but since we received this cmd from host controller, we @@ -232,6 +237,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd, } delete_info = (struct hci_delete_pipe_noti *)skb->data; + if (delete_info->pipe >= NFC_HCI_MAX_PIPES) { + status = NFC_HCI_ANY_E_NOK; + goto exit; + } + hdev->pipes[delete_info->pipe].gate = NFC_HCI_INVALID_GATE; hdev->pipes[delete_info->pipe].dest_host = NFC_HCI_INVALID_HOST; break;