From patchwork Wed Apr 18 10:05:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 133611 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5694911ljb; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/b7KWx7l4SX9NjBKxGthk5TQoY+oWJ9ARKPL2wr/QTBGyeZPCUnTFsZMNvY4CY+VZydzMQ X-Received: by 10.98.130.140 with SMTP id w134mr1407602pfd.127.1524045956346; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524045956; cv=none; d=google.com; s=arc-20160816; b=ExzlutLgE44q84Qip0tzPZloD/Wwe9F0sKU+ON9d+YXHSyNDFAUXrINIwryz/y/BOx 1Qu9u7T155dHknB75iXzWm7eRklwjR4bxq2p8AC/u+KlNNynJWm8iyGN0Pq78MkKtMAm yoy38/7T2GEYIEVAMEKUdBiFJl0BTzQM8MWb/t4FLYPpcNmlimAdwPY3TmBUW6bh8La0 hWhNscPUXgbAd0PD0jeSv9gx4FoZAYDfddUxaJ8B28n7nJ2UoM+NEXW17kSVtsqkxcjI RNMSakSKujqQzIzzf28Gg9V3sTc1cXUiYflZJNSXqQvpsaGw/r4nEyHVvKvcTE9sbBMF 7gng== 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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=Q+TFDEJmLomyYytBzrCxW60L6mgfHh9keS8yt6IQCLfWSCeR/i10qNECg39IfvADo1 RZpI1wsXSi9rz3wgmnm+Ok9+u6bBIfPriWabqgkdELfZj4Rw19JKapRxKrsOClp+vv3y Z7ddxpz3Wrz8ms8GNk2+wFh+sweIiSg3OmuY6sGezl7SnGSkNwMVRd4A0oRUN6QvwdLe eDo0tNq6zdYLrGQXaCASj2a4nm8j2zlJTNQBAWg5xiKYBhEVPVz6PVK7Z2hlfh0hN7Uc Vujm5XI4NHiZlvyYZ2ElWS8ycgIVawhj5pktc9rDfVE/nJkBkYgHsHoJjQmu6iJ1cFSy +l+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f4ScOL+k; 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 e15si793285pga.573.2018.04.18.03.05.56; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) 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=f4ScOL+k; 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 S1753426AbeDRKFn (ORCPT + 3 others); Wed, 18 Apr 2018 06:05:43 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45112 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbeDRKF2 (ORCPT ); Wed, 18 Apr 2018 06:05:28 -0400 Received: by mail-pg0-f66.google.com with SMTP id z21so626447pgv.12 for ; Wed, 18 Apr 2018 03:05:27 -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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=f4ScOL+kvsB1n2oHrfxVv7siv3wGHJzKQlab2ujoKM5bBCjc+vd79n3HDdSDM+P6Hp gPVgUYJtiRATXiFEv4omAat3hkGhHbwHoHKFXG2cnHVzU1SISvSR5YZLHvltIrk3Kv93 /xJqnQjFCQklk5b/HUG2RXJNccwlozf68YxsE= 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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=quvwO8QZ3j4FscdqsdsVHCz9RQrqjvSxsrGhw5utb7UkgV4Gahd278mAKDRsNPIjt3 MUQ6L6HnJ+qWGKxDuvHCGMpp82vwr9GlU2muoy6ObZw3qsxJmzrD1KZD0alQGnQz7qSL aXpp4GNT5qj53H6Sxzk4wBN4wBqWhyCexfzYBLmU3TsY1pK5yClWxnxBxcAaKyRkabUD OLv7nVf/JOpTXlnBdiPfinbEPKnwQqMdmvFkTY3K3Dm2Iq3+q9UKF/uilIquiulu3CBc 4vZ8IpcILMA+T20mjXVIzfDkwVgSUCtVNnlGuor9Y+HEdziO+BywKoyEJTtFKGAsLxEy ln+A== X-Gm-Message-State: ALQs6tD7ZZAG4Dm9/HsDbe8ynd6IU9siou20VQmNtTIOzG37voc7aswp VFo7yN3Xx9IGdtsTfOpK9gLuIg== X-Received: by 10.99.125.78 with SMTP id m14mr1231947pgn.190.1524045927437; Wed, 18 Apr 2018 03:05:27 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:26 -0700 (PDT) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Samuel Ortiz , Christophe Ricard , Andy Shevchenko , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team , Suren Baghdasaryan Subject: [RESEND][PATCH 4/4] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Wed, 18 Apr 2018 15:35:04 +0530 Message-Id: <1524045904-7005-5-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524045904-7005-1-git-send-email-amit.pundir@linaro.org> References: <1524045904-7005-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 Possible buffer overflow when reading next_read_size bytes into tmp buffer after next_read_size was extracted from a previous packet. Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- drivers/nfc/fdp/i2c.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.7.4 diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c4da50e07bbc..08a4f82a2965 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -176,6 +176,16 @@ 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, "%s: corrupted packet\n", + __func__); + phy->next_read_size = 5; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;