From patchwork Thu May 3 18:38:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10378895 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 44A9E603B4 for ; Thu, 3 May 2018 18:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C90F291C6 for ; Thu, 3 May 2018 18:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 204022923D; Thu, 3 May 2018 18:39:52 +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 A6A98291C6 for ; Thu, 3 May 2018 18:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751174AbeECSjM (ORCPT ); Thu, 3 May 2018 14:39:12 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39761 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751220AbeECSjH (ORCPT ); Thu, 3 May 2018 14:39:07 -0400 Received: by mail-pf0-f196.google.com with SMTP id a22so1309106pfn.6 for ; Thu, 03 May 2018 11:39:06 -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=bQVjZYBsVQrcd9EmtkKcL4YPUtSEKCns/vDF2NvsVJQ=; b=jsWz82eU07D0js9tGZjzfSYBz0kk5wGoEsNWOGQRAEVcwds7vuBdCM11sMleD4uvB+ kTrNPCy+FoW9ddgFGMsBZ9eXJBJcEq3CCdrHFVQbL8KigRt6lMw7EzaXUbf8BmBfah65 1FIJeyL8v5qks4/dUArzGWp9SsNPiENuKPCwE= 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=bQVjZYBsVQrcd9EmtkKcL4YPUtSEKCns/vDF2NvsVJQ=; b=ZgDlsrvHozVSYhNx611FEFQX9qNW8gYdts6Pw1+kIT/TBCkZ/C9BuOay7p7rMBMyOv 2Ji8TP1kP6CCLkiwkluTv5CZkUtkOLlciBvlPLE3jcJT4q+8zX9lC63YLOWhfSqGMqDO Unt2WacvsyPnzB+UaOu5l4obp9Q0tDQPH63yV655aS0D+pY4avDoKV0A4vAAjb8+jfyY onQQSw+7ZNMVxsL0uVVf9Dt8smfE1f5idrCoDgy6b7I1cgdGVjGicr/swDbPq055Q2u5 bWeaW9SEk2SkTEMIC5mGErGL4NKSKTJv475qDa9x8c4XYlz/zM3P5HZgBBtsP1GE8X1g ct2Q== X-Gm-Message-State: ALQs6tDLkTVbHSyBf93waf8X1YURr+pkjPpz+8SUq/smHlsmM9qVOQRU rowbpJ2pxlcxoQ/m/J4P80SLZA== X-Google-Smtp-Source: AB8JxZonBjbfVrJfdSQ2mzDF3IDb5ZEhljE6qQJ3WI3SOVLeulrzyHlPB8DYSM9qUQWs0dFxLqiPHg== X-Received: by 2002:a17:902:700a:: with SMTP id y10-v6mr25151894plk.265.1525372746484; Thu, 03 May 2018 11:39:06 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.226]) by smtp.gmail.com with ESMTPSA id o5-v6sm4130786pgv.47.2018.05.03.11.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 11:39:05 -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 , Stable Subject: [PATCH v3 2/4] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Fri, 4 May 2018 00:08:54 +0530 Message-Id: <1525372736-25094-2-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525372736-25094-1-git-send-email-amit.pundir@linaro.org> References: <1525372736-25094-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). cc: Stable Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir Reviewed-by: Andy Shevchenko --- v3..v1: 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 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;