Received: by 10.192.165.148 with SMTP id m20csp916368imm; Wed, 2 May 2018 10:50:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrbBMgf1/2L3z4AI6YZUWvgxMOWKIeJZw9z1clX5lH6ipSU8D4D4aZCl7tXU0qvMxZHddxp X-Received: by 2002:a17:902:8a87:: with SMTP id p7-v6mr5787473plo.278.1525283451959; Wed, 02 May 2018 10:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283451; cv=none; d=google.com; s=arc-20160816; b=shBRTlf3LcVek871vJAlHcF4lX1i6XTGhY237i4gUIAVLLbYa6BwB6oYs5IyXpGbeM oZPnEZr/3Q8Dbc71aIveEMmuo73cq/pEC1s9OJCdAORphnj1kbCwkext0wtjeFLm+dpc TGtyYYBi0g/G58btmHtRW6GUXYtiDzFP5AdLse9fMZsIEBo6dgnfnHYXXj5Z/0tlF5iL GoKw+kJ1w5d/3ze+pPjO/TCwGL3rCMB13PDVv/RQfXBw4hHAo2aV4oSFagTGL7b7JnZg 9qTTk0f/KNF+YOfldN+UHO3ksMRaY6/GKumadgim3bp+Bz6xIRNQFji18gny4Mug9uYA LOgA== 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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=0EJ8vMkgdwuJBR+qxlLLD6m1gmmvwXgt3ClaOE5UVgfvaq7CxOHKJTiaipEwuTIMky csEHZOYn0Hdmw8BjTTarCGjfwnNyOHAm+PVj34uS3pvzYtrt70U4I6I+RfjSTbICm9eM Lf3om6bJaBAOqSRKalSh29yPvdukgIUiKyZLVtoTN+gRJSjQEr4WlVRGf/LrPuyWF9r1 Kb/7F7GsXcomZryuls6wObf3GaFOrJwOhXWB7AAL0d0X1D9dHABM1fPHKl2r1o7M5crY WhDjuTcWQDTP/AY2fi6Ea+6RqQDxPy5KYQa8QbjZ1Y4lQrpMi3gBS9t/ApSPDnQh6dZL E0OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fJKe5FX7; 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 b6-v6si11355829plx.211.2018.05.02.10.50.38; Wed, 02 May 2018 10:50:51 -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=fJKe5FX7; 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 S1751835AbeEBRsk (ORCPT + 99 others); Wed, 2 May 2018 13:48:40 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39340 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751837AbeEBRs2 (ORCPT ); Wed, 2 May 2018 13:48:28 -0400 Received: by mail-pf0-f195.google.com with SMTP id z9so12400328pfe.6 for ; Wed, 02 May 2018 10:48:28 -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=lX6FWIn8hjzqTKMv8Ow3zBWjvKq2dzVioYiHLXy1F701QUdiDIwx7VUBAuFuuDKFOj 5dYEQZJxY6hGqFwOTFWLVMxtYSBDZNR8tbWP92KHudiQDk8SkvspDkTj2JnI3ZUkYWKl +2qQKtr6iV3YxrWdU2kZqkufYwrq+xuvsTp8d85DSf/yFpmgc8B9Leyd2OEQPcCnWo7d v+Hb1DmEGaZM8SIOwYV561l56S8h2JNq59Xtrb6qdpG3225YPTIKoiH94uAkzHLuJl05 Hy8QpmzjbxC0lvPBZUVnJFqQQQO4Fo7DbAsiKLOTpJO68GkliWIwyvkeAm7xTsLMR22e 9RHA== X-Gm-Message-State: ALQs6tD24hMqc9YHW05lOyLcBWCv6ReyOh2rJzgICT4h0/1VOv1u1dEa Id0xh1Oq9AHLeyPga7fZM0KJcV14ZMY= 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-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. 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; -- 2.7.4