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: 134854 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp960973lji; Wed, 2 May 2018 10:48:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpB7iZNinK+v9Zcz20F6hqfFUljAy0r7yIQLQ9BCZ/6TOVFrz6hWOQwoyF8fr7pWbbdgNqG X-Received: by 2002:a17:902:ac96:: with SMTP id h22-v6mr21046075plr.338.1525283322508; Wed, 02 May 2018 10:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283322; cv=none; d=google.com; s=arc-20160816; b=d/hQgVynUc5Itbxr7lMsjg2VjYjCqW/+ADcjPOS4uggdfmniwWKDNCk6uiET8c7aO/ fpc+7vTUW+bNI/jTE74DI1P8A361vTcrh9RiQn7jkMKXDgjjfB1Z01NyGHnRpdfnAcpj QueNwEfVHx6m6J+r2t7lrBPmI7Usy6TsH4YlEFCMvQRPwThrtf4kpWGzJtgJUJ7a1OtD vcr4T35cPP/b5UwCqi7UzBbGYMtG1rCjxRfqpI5Bj09W1wcDDlnlp7Qv15Dw19+ximwP l2dGIIQgYevPz4j49Hei0E7oMVnRVBhEMKCJeixs1dSiGnnENcn1xGbiqerImyCbobdG RWjQ== 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 h62si11818453pfg.308.2018.05.02.10.48.42; Wed, 02 May 2018 10:48:42 -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 S1751852AbeEBRsk (ORCPT + 29 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(+) -- 2.7.4 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;