Received: by 10.192.165.148 with SMTP id m20csp2166394imm; Thu, 3 May 2018 11:28:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqYCFSQWhfK9u1YQRtqSZMNYVEaljYdtGQ/8N9nXSeshnmYZiH185YUYbVvKTZsDAUR8L74 X-Received: by 2002:a65:6398:: with SMTP id h24-v6mr19522500pgv.170.1525372127672; Thu, 03 May 2018 11:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525372127; cv=none; d=google.com; s=arc-20160816; b=DWfxk1QsWYrzkYXigsNjYJBKx/g29FLTJ0UtScaPISAwCLl+gyE62WM8DsosxFwxPr SNt95/H9mv+vJeDfr0L/EN36eOwsSNE/6dnsYuC4l34X/PPJaS5VXb8/SC/34buhCYhS CiE/H3BcatRLub5Kc51fbl2p/5m8r85nwT8l+YkXJoli2AQQJ6rarKSJ0aZQlJBsVSsi 8SxUlKDiHQEK0O+boxtzMHRRMt2pDvzDSY4iQpr7BlDlQsT0m+qBmOETxvzWQxGG+iT7 uRcgZ0cIDpaZ9sbJ4uApi/kvbn5O/4uzBIuDf3xBQwa8ows4Brz7S6YYnKjk/TxDEbQ5 6FEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=5JhSmIha80rvsM71TEKS2B1PHDtBWa9m1AeBDujcKH0=; b=d/fO/aRlVos3XEPjDGu4b3RuDtudxpTkPyn4lz1kQcek+eKdseGifOBlvYi+MaPf+l GP4dcC2AwS3Ij4i9G0HxZaMBfdjzk3rDHxXrhlL3pKDz7TWz4ayMHOhDA40KKcwRF1YV 48YzPCDdwSu6UvulxU0A0t+kvAIUs+9Q5wvKh/pJs7BBj6m4eeV4FD7rxkPOBseskOJR aAgjdOOahkM7AaGtWQOCzvLOh8V7SXVCdW16Kmsj/kvRY7arB0LYFhGmG8cJlX45XHPl 1IhBiV3VvfryzogwQhq0x+OA5XSHUwNl+1KqfO4k3HJMPICPvgRYz/Yd8kdJF2/lqeYj c3qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=COHtBq7F; 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 k5-v6si11763296pgo.673.2018.05.03.11.28.33; Thu, 03 May 2018 11:28:47 -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=COHtBq7F; 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 S1751377AbeECS1k (ORCPT + 99 others); Thu, 3 May 2018 14:27:40 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:32981 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbeECS1i (ORCPT ); Thu, 3 May 2018 14:27:38 -0400 Received: by mail-lf0-f67.google.com with SMTP id m18-v6so27396726lfb.0 for ; Thu, 03 May 2018 11:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5JhSmIha80rvsM71TEKS2B1PHDtBWa9m1AeBDujcKH0=; b=COHtBq7FUM/MzytQledTXcxZWOiD+rTqUfiQKP+ZB5twOfgbew4UJvhmNZYcz1mTJG 8ch8hvXL9KfmDEXw2cEQj23wRabHcFCz5Wvdy8yMtskFDfdbOtxPJnTobmU0YKG842Z8 0QXK7X9UyF97cNFsARcbWUQpkNCU4xHISaoyA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5JhSmIha80rvsM71TEKS2B1PHDtBWa9m1AeBDujcKH0=; b=fl1PBYJRM/yGFPqwONUibf/XYFStmkdmcan3MLmfABcsniQm0mNoaMCeo8xIKYXe2H WH8PuCZDkwxB92ZNAit4bYEc37qQxrn/AvI9FrFcuxEMCw7yMUZ+eqBLoneawOeSlHHy 7zCLk7fUTjb/YEpp8V9OkKaF3bAjB+jAwH/AU2gIweDUCbDkf3557zO9RWSRk879YOpf rlPq0Psr3EUBcC/WcMIQ+KwckdpVdDL53cSZpW+PcwcjW7Io9yoMSrQkXmMvwicf6tNH B5d3514GM3iLTEJd0alF5hGTYetVGxAGMFBpUqhyQ0gO7Ax70lTH9c6kFieq1+4ae2us fTfA== X-Gm-Message-State: ALQs6tAqH/WkOVkFj4DV3EpQFojTGu41BvFEV98tTQuW1VONMyVEt6Y3 o7jJhCbkpOE7Ki39KfbAeEqm+D0GyANE3FgvOiktPg== X-Received: by 2002:a19:5791:: with SMTP id l139-v6mr16062572lfb.46.1525372057142; Thu, 03 May 2018 11:27:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.131.76 with HTTP; Thu, 3 May 2018 11:26:56 -0700 (PDT) In-Reply-To: <1525342843.21176.635.camel@linux.intel.com> References: <1525283288-7027-1-git-send-email-amit.pundir@linaro.org> <1525283288-7027-4-git-send-email-amit.pundir@linaro.org> <1525342843.21176.635.camel@linux.intel.com> From: Amit Pundir Date: Thu, 3 May 2018 23:56:56 +0530 Message-ID: Subject: Re: [PATCH v2 3/3] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver To: Andy Shevchenko Cc: lkml , linux-wireless@vger.kernel.org, Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3 May 2018 at 15:50, Andy Shevchenko wrote: > On Wed, 2018-05-02 at 23:18 +0530, Amit Pundir wrote: >> 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; > > Shouldn't be this magic replaced by > > phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD; > > ? Ack. Fixing it in v3. Regards, Amit Pundir > >> + goto flush; >> + } >> } else { >> phy->next_read_size = >> FDP_NCI_I2C_MIN_PAYLOAD; >> > > -- > Andy Shevchenko > Intel Finland Oy