From patchwork Wed Dec 20 19:51:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 122492 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6023561qgn; Wed, 20 Dec 2017 11:51:50 -0800 (PST) X-Google-Smtp-Source: ACJfBouVQnt6vDCmLY4AJAWTaSpFxcbG7L6sG0j4lPMg9fkqXw4rK//vNOVcZnKQJanZDnOYYN2p X-Received: by 10.99.101.66 with SMTP id z63mr7424755pgb.426.1513799510042; Wed, 20 Dec 2017 11:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799510; cv=none; d=google.com; s=arc-20160816; b=MhNwi0O9BorlKuY2AVaj1PYnI9qoHx+A+Yb4oNnPbMtQcQrXuxWjb7n+JbjOwxN+kE yyAFmpQ8oAHY9Jhlmb9q3q+Mc/dy4Xza3gQNhtMyJHBqbhoUsg17hOOE5WSrL88RFLbq aKbfrrFs67fO1EFjPdK8iiEEtbO/jdUbMrfztpI33Xpy50erDaMzpOASqyn+JrfAe6IY 4mmgeu8WRsOsm7tYXYA8PWJUat8lorWFCXtIf1QbTN6lRzVzlGB0MV3EwCfHmFNY3NaR /r0VF3C9QoPoU+0XMV4Ug/d83GT0OJYfosza1349gJVYTD45e6cldaKHj4J6HmDxikzJ uUFQ== 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=KpKW3aPjV82SBufNPUgvSXs6uQzi+sN1usCFrEYrpYBLc1fzeYgx+fvzGNWo1wVg4t lMrFQ4PVVvRQ+5UJU1APPMLNQz0tQOs3mxrcdXi/L6POSmqmvuboVxZfCulPw1DMZsUO TFNTt6dFyX6NYolC8hFDROLR5Xql4THxjXfN//1TzKNRoet+1Wh6G0wF5wmvNmHfksDg 7SrpuXGcO+UHnDZD+XurQSpKJPD4FfzR8vCCuhcMgsUrgdV2MeOu5ElNSB4EHgKgUSps ++tZy1xlN8qDSOjpN1CsTBvPvsYJIo4bSkac987WWjkRfIAVSBWsfIgeU3qIGhbngBJb y17g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ictfZkm/; 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 i9si12288544pgs.523.2017.12.20.11.51.49; Wed, 20 Dec 2017 11:51:50 -0800 (PST) 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=ictfZkm/; 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 S1756782AbdLTTvr (ORCPT + 2 others); Wed, 20 Dec 2017 14:51:47 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42671 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756746AbdLTTvn (ORCPT ); Wed, 20 Dec 2017 14:51:43 -0500 Received: by mail-pg0-f66.google.com with SMTP id q67so3092573pga.9 for ; Wed, 20 Dec 2017 11:51:43 -0800 (PST) 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=ictfZkm/czEh5F5dX0Q+WEfhCfrkDSDHdL09pN4GGlqU+HfXSdt4sH/FK5qmHKglUg 8vyEkcXVywZmq6cFj4NYZppAD9XIq5eZhMZNGBrIVmlwi/3yAZ+lqGIyBx3A36Njod3O 2Fo7U6hgUDbiyVKh6T8BEwpmU0ErAaoQtxra8= 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=pCrxMEMWigXTGEJdaWLSuQsMafC+6qSXtRDnTNX4gOQ3XaJavU1y7pa1VDpeGYbO8Q nc3ptbvPujnRcQaziP+RuRVW4BaXA/e7OfjnPQyQmkzFSocrIdpT6+D9JEjl/1wQWE3V LngynDQdTbaJSjpYO0VtnO52Cf6dDx5Iobfgmr7oMiAMf24LDg64haVd6meeH6VyXOrp BvYGYUo8bqvUuP9xeTiGKDuanExYlhOkUSrgo0SD/un3LDiAMEPMFmdAIqnlf4el2n67 CINZcStfmOvTpt27/STzZp0zIz3JYFjWyoeCKvqfiDNWsHzEmxBUsQqMwyO3gZcN2BlN jiJg== X-Gm-Message-State: AKGB3mJqoAry173oTOXlbs/wdZQM8TH/en4zA6NUsNQnU4axrvzlDNch 81Srd4pv+ysRWFrqI3q2AcqsiA== X-Received: by 10.99.113.20 with SMTP id m20mr7196139pgc.67.1513799502880; Wed, 20 Dec 2017 11:51:42 -0800 (PST) Received: from localhost.localdomain ([106.51.17.191]) by smtp.gmail.com with ESMTPSA id g2sm36715867pfc.130.2017.12.20.11.51.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Dec 2017 11:51:41 -0800 (PST) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [RFC][PATCH 3/4] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Thu, 21 Dec 2017 01:21:23 +0530 Message-Id: <1513799484-12505-4-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> References: <1513799484-12505-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;