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: 10347749 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6E0F60244 for ; Wed, 18 Apr 2018 10:05:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A661A28599 for ; Wed, 18 Apr 2018 10:05:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B3EE285DA; Wed, 18 Apr 2018 10:05:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223DE28599 for ; Wed, 18 Apr 2018 10:05:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753211AbeDRKFZ (ORCPT ); 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-Google-Smtp-Source: AIpwx4/MFzvpygyNaDfvhT4ovxWSIkvrc+6cih2Djin2yFEJlMAmYx15oG3McMRZ3vm+jK/m0Nc3vg== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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;