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: 134853 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp960798lji; Wed, 2 May 2018 10:48:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZorlPzJISzhif+gL+GfeFHeuU4VEOMLWfZlzftvMY2rh64d2WoEfNJkV3KpB1XtBodabhSx X-Received: by 2002:a63:b746:: with SMTP id w6-v6mr12138197pgt.215.1525283311711; Wed, 02 May 2018 10:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283311; cv=none; d=google.com; s=arc-20160816; b=vDhMiKq1tu9QiG9TI78rcmpD5jwgVjlCHsI46NwrR4ufwOHLwkdp9hS0t043/BTD8M VrEVZnVE/YLIdSrXysftLl2pmBAyEK+05RCMYI1pGwxh5WXg27yUSOUPCSQRFv3jKJyV MVoqWaPVDVVQTXaKUH+0QvIDSCAohi6lhgggu31IJHuZWSig/iyoMlTqNSpQSw+hpWK/ oPGZXMNLDFkt9S97h6Mbj0e27z2g/mh13JloVLIyYgP7J4RmljWQ9DzcflmjOXT5IdVJ xKG4CrqsX3pb3XGOuhNoHurk5Fioq+Le1zJEBmrSWBQMFPMCzhxwcSht2714iiZbx2dz DM/Q== 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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=IQ8+z262xFstmMYdcSq5KPQoaMDS+f/l1pUhLQAfssB/q3ejZOzVqUShkXkJyuqLo4 pkMPLKGJD6SgONCj2F549Sd1sfSrQktcfQvPOm1VMnUPzdN5Bew/L/lX+v9sgfMGuSCl HevSsejRBVEMxgvaph+9OsvbvwgtG2Z/1nY1pt7D0mPEFXoBQ0gb8wpFrM6lAdr1Dajn qq9kF7bEbunQCCbOHm7VvouEoi0q5cDbouR/H0zlcBLkfFNCbwSy5LNS+uOnvSKGaiRS H4lphs+iOKu673OWAxrviEFNDbasGrwuBxWgXP0c0rgXAn06VXbN1k4S8JDE7UeJKvbd oXsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=djnVsbdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 u184-v6si9757258pgc.223.2018.05.02.10.48.31; Wed, 02 May 2018 10:48:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=djnVsbdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751846AbeEBRs3 (ORCPT + 29 others); Wed, 2 May 2018 13:48:29 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:37087 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbeEBRsY (ORCPT ); Wed, 2 May 2018 13:48:24 -0400 Received: by mail-pf0-f195.google.com with SMTP id e9so8414267pfi.4 for ; Wed, 02 May 2018 10:48:24 -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=R11s5xNAeajtnpua/OgDOYCjrykwOvyIYY8KSiEBtS5nYdLkE6B6U+OzHpoorRhA6m vfTmjXwXw8fAlMZq1p1APBytT0mV+V0FC335OZRWhOfbmIVdEAnq9I7LIS5Q++0VBtN3 KYkxOmrvPi62TB3UqkqRYKMn2E0E9mpzOrJIZLQVbYkrcbkngLwinPBTiY7Y4+O3n1va BSMKC5p34aZpkb1YstHRWvHfUQyGFsHLOHzkRbJu0dg1pjHuxIFFVYmU+YQC1Tbj01aq FZvXzbn5pfhIrH9BbL4BvVwhBp/+kn7cc+JlJnbApZzbwp+UXq5KT+UDE2zB8sZPFBgb 4ukw== X-Gm-Message-State: ALQs6tBBWOAyxrJtdM7Y7MTS1//fTk3pShTAneIjug0wKqEtEbsNN7aa ++vmuoiKpfGV98bfeuXJcvw88bwBMlQ= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- v2: Resend. No changes. 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 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;