From patchwork Wed May 2 17:48:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10376179 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7347260384 for ; Wed, 2 May 2018 17:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 653BF2267B for ; Wed, 2 May 2018 17:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59E92289E2; Wed, 2 May 2018 17:48:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9A12267B for ; Wed, 2 May 2018 17:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751522AbeEBRsj (ORCPT ); Wed, 2 May 2018 13:48:39 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40251 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751835AbeEBRs1 (ORCPT ); Wed, 2 May 2018 13:48:27 -0400 Received: by mail-pg0-f66.google.com with SMTP id l2-v6so11150686pgc.7 for ; Wed, 02 May 2018 10:48: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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=fJKe5FX7XaJ/Kmp+Ss+DUfT8WypJ9cUdcNIgDhMDcd4vmTac4mMwTxvu27HDLrrzvQ 8iq4oiuYd8HWt5f5B6cMWKhEOhVEQoIZqbxnuSsSaudJug8WvI5ZXKzy95jPQu+WYp55 5YwuNiga6gX11RGVE3+4vxgUZiU8ug+tixfjU= 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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=JUkcurWcD1aJSJiKDiJrZW0Rq497ci92pG7D+V3eqneZ4EL1jLTpFx9aFOjbL/5GlB rvZGFYcaxTUJyz0ZOcyqLznUoRVTFUGS92ajArfxWAyaxyLlY0FRjopf74xVU2AfygZC sC39PMdNFnjoppB3NO/V2esd8NjLN9aiv4iEqQQkMK/dMWrJI9xrPR1vtBG6XuVLs3sW 78Uilia2fBuphp169g3A3nQE5zyTPn4F9CXf4thg1ZLpJpx/OZfrw7n5oOX6oCFjz8vH i+ETuNkW6UAnotnJuWQcmFfUmO92nuXlWQEIGcLomeKnadPN7bMCZHoFlmNJM9NSAVxd hfxA== X-Gm-Message-State: ALQs6tAogLaSEknJz1wTsIp2PiOIdjEMkO3M0sK9DDMLGjuDjEoFHfOs kPXn1tvDeLuRiBMBNW4/LS2xBg== X-Google-Smtp-Source: AB8JxZojhh0TbktAWfCoy1QIAaekckXeLu2iSzvhqfuLBAvALZiR1ypd5E1tZW/QNdw6uSDfHCdBJQ== X-Received: by 2002:a17:902:6b0c:: with SMTP id o12-v6mr20673823plk.159.1525283307320; Wed, 02 May 2018 10:48:27 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 10:48:26 -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 3/3] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Wed, 2 May 2018 23:18:08 +0530 Message-Id: <1525283288-7027-4-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-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v2: Remove redundant __func__ from dev_dgb(). drivers/nfc/fdp/i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c4da50e..b80d1ad 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 = 5; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;