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;