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: 134918 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2256044lji; Thu, 3 May 2018 11:39:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqd1YxN+88UfZ9TAFoNa7/TvtaU1l2BeXKQUe9voBot+3/LRiOI8kohX6X2I+xFhF5xzDOD X-Received: by 10.98.12.202 with SMTP id 71mr23909814pfm.61.1525372756438; Thu, 03 May 2018 11:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525372756; cv=none; d=google.com; s=arc-20160816; b=aDNXvZIgIfcpYHSWJorLEQ6WNkYtxU2sShndkt8E7QvuF403RStfqZKAwwjktVpMur 2Yt2nww/Ha2XSyniojixKpUZ0CMLz1Hjs0RfBVkHIDG1cTOU/kL+VRJC63YLtP6dV1CT oiW8U9RxpC8Him1mXYtcR2xlRPcRaOc9x75StbP/5gUSp1veKPobuy855yEnBsJiEPcJ m9Y6QWwId73k66FNRuIIllPI0NcavyxYRq67bC/23UJWtha0b7QR0oVFURudL86dEFlz DUGMUSTbTbaQDIstixRxGS+zlEXy/Y0JlehlKHaJiIb0ActYsvz+zl9A1l7lMYe3u/gN YSIA== 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=bQVjZYBsVQrcd9EmtkKcL4YPUtSEKCns/vDF2NvsVJQ=; b=RUXbQlGX7Egfln6F0IheeK+uPU1pSscAaJSYR0b2H+7kgLvuJXQ7aHrk4LVrgQjoTV XNNXVgLiQ5LxFMvxjULcNdO7C1a4sg3LxV+FYCk3+e+7Pv3MWjgneICUQWjc7Bl55LlN 2gzuUgLMT5kQlN6DQjpefT+3xKNV9D9GOyu+8Xqn0LhXxkJD0n6McMnCAP0m6z7/LviA NV9Bt6LoYmojBrKyRjuC/cpOXFCuLqon+WadVA+aHtWBJkC7Gb/zNLvyMPQKsSaUO3l1 3+ZGDWqktNbDeop59O1wJdw+C3uxGNhVhcKDK1t4/AvJ46yL2YQb0wTUEVv/jVpiKGNh MGMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jsWz82eU; 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 u186-v6si12050385pgc.67.2018.05.03.11.39.16; Thu, 03 May 2018 11:39:16 -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=jsWz82eU; 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 S1751360AbeECSjO (ORCPT + 29 others); Thu, 3 May 2018 14:39:14 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35154 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751302AbeECSjH (ORCPT ); Thu, 3 May 2018 14:39:07 -0400 Received: by mail-pf0-f196.google.com with SMTP id j5so15417477pfh.2 for ; Thu, 03 May 2018 11:39:07 -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=EHx8c0hhGg9JzqzRriqrnXUak49uYB6Xro1Dqbce8Lhq0khsgGIcfKd5r4LhMy6EGC TUSQG7IS72KeDUP/W8FVVE2yktchWyqHPyk75iHvHwESahHghaTP8B0GxST2rblUlVoo IFrUiZN/6ZJT1XV1NlSBdk2Wu/Hr/JXPeBdwbUf5Z24GLfWxsrOWAv51d8PDc7opFiWf sukOdIIJUqut4ayCJISdcxSBQc+hmVdkW7UGStjFj0ps3ZdiacGEAHecnFkNPQnB1V0S vD51rBiMuFo+rlMo8GKK2u8TvEPdij5uPGr2MeqJfpup6hGCMJDhuRR8NF+JCtM62f4T pCzQ== X-Gm-Message-State: ALQs6tD9D17uAe3c5T5pyHxLV9WKH9RvlEYer2H+TkriMmLXarfjVfzT mf3acx5tuxUA2cWjL0k/GvAz10YH3q8= 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-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). 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(+) -- 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;