From patchwork Wed May 2 17:48:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10376181 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 D960F6037D for ; Wed, 2 May 2018 17:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB6692267B for ; Wed, 2 May 2018 17:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFBC7289E2; Wed, 2 May 2018 17:48:58 +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=unavailable 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 50FA12267B for ; Wed, 2 May 2018 17:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751220AbeEBRs5 (ORCPT ); Wed, 2 May 2018 13:48:57 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33148 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751347AbeEBRsX (ORCPT ); Wed, 2 May 2018 13:48:23 -0400 Received: by mail-pg0-f66.google.com with SMTP id i194-v6so11163086pgd.0 for ; Wed, 02 May 2018 10:48: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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=djnVsbdSHiXGUI3L7k1vTen67hc4ydsopoxbcg5aQKFjpdYkrA6wF/G7pDJv88/jiA Jd/fSkRFJkDMfOL3UfvlcdDTg1QbVWKrk2qQpvvymDRSCiezYRUhQga+zD6lsJTMPn/J 8+0KzoKrC8aX632RAIikX1mXP2/vNtogb59YE= 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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=nxpis1ucKVflkgPWan5ASGvQtMGv2Zh8OPXR5Do023Wvqtkz5zUF1bzPTCelMWWOp2 Hj4xMZMzdhx6zbkzh+gB4ykzwhfXg91sgJiJYbT1qs3CxbHYSAgjJTzntzEvT1kWeiL5 jjxD5I1kG72O5fp+SAeB8BaoXwnI6ee/BT/UfSF5MxI4r/K3O57GMPhqEj5k8rMZcD8G o0xSJ4jlGTGYjCPGp75z2SW8g6TGgTdsK7Y146Pb83tjO7f0jnzyoj1lye2aoX5LDYB6 /VTwtPHyH8JK9MQ+TrzHuYBoxsHxIwrLSpOrM6o3nPoADs6URwkKte/LMDhr7qMr4tOZ QJEw== X-Gm-Message-State: ALQs6tAngI0uwHicRU3Nt3lPOwR0OgQc4cjObn9K+yF22PM5yYct591P XtalefVNG+1OFoEsqj4CirqZBA== X-Google-Smtp-Source: AB8JxZpePEAO5Srxckv0RyNKCGQ9RbIbze61W4GYNhkxSQvrQN8shUf4O7++T6uz5lVv8naUoWyNNA== X-Received: by 2002:a17:902:2826:: with SMTP id e35-v6mr20947133plb.348.1525283303179; Wed, 02 May 2018 10:48:23 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.226]) by smtp.gmail.com with ESMTPSA id l19-v6sm19179875pgn.44.2018.05.02.10.48.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 10:48:22 -0700 (PDT) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [PATCH v2 2/3] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Wed, 2 May 2018 23:18:07 +0530 Message-Id: <1525283288-7027-3-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525283288-7027-1-git-send-email-amit.pundir@linaro.org> References: <1525283288-7027-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 --- v2: Resend. No changes. 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 ac8030c4..19cb2e4 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;