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; From patchwork Thu May 3 18:38:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 134919 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2256091lji; Thu, 3 May 2018 11:39:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpqwnD/hMqigWjCxL7SfCudmhqMjJOpuEJVnL7Jlx+fuqJSpr+OsWKWcrXl+uCxHEUZqJT4 X-Received: by 2002:a17:902:125:: with SMTP id 34-v6mr25563722plb.42.1525372760118; Thu, 03 May 2018 11:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525372760; cv=none; d=google.com; s=arc-20160816; b=RM4dhWe9O1pjesTqIEk9Zx+OsWh++AlHrjMs4Ak0pM9LiysWvPDXpV8PNX7gMl2olW tCaUeXEg2aA6K0ejuv4J7QLAw/YkWyrQ7eXtL05qeaU/RSTDdTYcQgEkx5mkHhem1IU8 kYKpvt60hKsUBYP+TctLL+42pa0Ie0jCVyz0ZfthjXzWxhUuAlXDYA4s1CgTHE6OUfSi bftC5BYG81o+la3/SlkMUow0Nf8JrGZ6VuyrKiu0AIxwE71ymcMhEDG9AYAeD6ITx/Jh ksaOVBsg/JapSPTNOezpEMPqReyVm4TwNRevzcg+ieYOQB1oPqsQiw80yAoKynKiK2H6 ywHw== 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=xcTzDdC7kS4mNsgue4/ljEInDC8m7hROwHlFKZV6S2A=; b=cWgmgL/U/RQPgIc2mNGCiRa9sAL6Ws42TI44BXjxKhcm+YY4QUHoZ+aBIr7Afzc+6Y hCrAib2xPDJTj7zxOaZeLXYWKxTkObpkIyRiewwnHjs7tewDhhp8QarGVepIToNs9mMR U2n5eXfwcLKY1diwT7UNxG5BC2OP0HqZ2lecHyAYz+IVuePOSSF6I+VX9YuMSZ3WL2F+ L/pYWAUxQs236834Q0le5LwjZ0bXX6Tt+xz3vIbfuBGjmS/hrWvRgJzogCJqYC6IPhNA V6niEA73k966JaflwNDkIsI4qxQJrbly2w86t0W36kjsL2jJJd7dGwgFsRhu13pj2lPC pydg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b/Z2FoHQ; 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 b73-v6si12028537pga.106.2018.05.03.11.39.19; Thu, 03 May 2018 11:39:20 -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=b/Z2FoHQ; 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 S1751403AbeECSjR (ORCPT + 29 others); Thu, 3 May 2018 14:39:17 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:44880 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751307AbeECSjL (ORCPT ); Thu, 3 May 2018 14:39:11 -0400 Received: by mail-pg0-f66.google.com with SMTP id 82-v6so13720891pge.11 for ; Thu, 03 May 2018 11:39:11 -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=xcTzDdC7kS4mNsgue4/ljEInDC8m7hROwHlFKZV6S2A=; b=b/Z2FoHQadStTl9MRI1QOPXDPek+lb/owsHVmVfQGbPapexttKFhyTzH2eP9ljgkU7 c+r3y1CFWz+PS1QhgjqhzmS8OO4soBVAkw2b5mmy9Upa5EYWJIMIBrLfCpUXlQNDt5Dr K+cKx58NDXg9FO60wpXKpeBTtiRbiZ9Ckrk88= 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=xcTzDdC7kS4mNsgue4/ljEInDC8m7hROwHlFKZV6S2A=; b=dWBhQHOcN9SVI4CocrVNi1n/aE9K6H7cqICnyHcZw4eogT4WlozfOIfJQCwJ+rpGRw 1w5z30ZAdwOi72cK7Sk0dI+9cpziVPI9LbVqPiBMOBLO1QXkK4tu9vVj65OwqhOaEp80 zEpDUbv4fZurOL4Hnj/84SOdzzvhbZgLi/Kjot76Ub4qZOcRotf8J8duj9eWdA43VIOr f3Gj8JqZfsqTSBmu+ht/FXWWZ1d3nUWJGxEP577W7UODc3crIsar3S8ck661K3XOZUss qJhHPIibsISqIq9ElmJIGN0yURIBQuVBf+WkMszDr9WYNQLK4tfcVnF2BtBWg7gLqAIc +NUw== X-Gm-Message-State: ALQs6tAs4PBeriiBCL617pYeRXlVx1VKTQxx08SgL5xcuAa1hOgAVkKT L9uThioUn5Dee5T4ay+tgPFmbFumeQI= X-Received: by 2002:a65:5c88:: with SMTP id a8-v6mr19662997pgt.373.1525372750698; Thu, 03 May 2018 11:39:10 -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.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 11:39:09 -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 3/4] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Fri, 4 May 2018 00:08:55 +0530 Message-Id: <1525372736-25094-3-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 Possible buffer overflow when reading next_read_size bytes into tmp buffer after next_read_size was extracted from a previous packet. cc: Stable Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir Reviewed-by: Andy Shevchenko --- v3: Reset next_read_size to a more readable macro FDP_NCI_I2C_MIN_PAYLOAD instead of 5. v2: Remove redundant __func__ from dev_dgb(). drivers/nfc/fdp/i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.4 diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c4da50e07bbc..2c5ed2224c5e 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -176,6 +176,15 @@ static int fdp_nci_i2c_read(struct fdp_i2c_phy *phy, struct sk_buff **skb) /* Packet that contains a length */ if (tmp[0] == 0 && tmp[1] == 0) { phy->next_read_size = (tmp[2] << 8) + tmp[3] + 3; + /* + * Ensure next_read_size does not exceed sizeof(tmp) + * for reading that many bytes during next iteration + */ + if (phy->next_read_size > FDP_NCI_I2C_MAX_PAYLOAD) { + dev_dbg(&client->dev, "corrupted packet\n"); + phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;