Received: by 10.192.165.148 with SMTP id m20csp314030imm; Thu, 3 May 2018 21:09:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqT8TBKWjG6kret228CnNW4qyRpliJFmganItOnnWIV2bOb18hP8dHyeq5UfSqsa4IiPJkB X-Received: by 2002:a17:902:2f:: with SMTP id 44-v6mr26818964pla.187.1525406979083; Thu, 03 May 2018 21:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525406979; cv=none; d=google.com; s=arc-20160816; b=M1L0640f8P+SscAMKyx7vMUjIVAKZumhbAvSDQZcedi1pk6orHZIgrDmxrekP4iCTS pSjQvbiThlW8BIm501E0fOldsny40y5cvWG2J79GH9wKpSnO0Jw/cKxdP8ula7Gq7Ptu Ir1xMRjsPSlucwatxdzMhyTSCJ5LC8wx2yzjmcU1vGkAZayP3/HUyzFiCe59vA59h6TY lT5ODLCfIgtg14ORFjzxBPJlcqvGuo/MEq78w/uR8pTRhdOb2f5Yp7PrKkHo4bY4c74F RSVdZzm8QoDBbOv9VdqFvtYqvlBsEZmpiCPLgScjQtopt4ijk61lPJNmYNFK3jjwHJ+z vXAw== 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=spdU29jNpMPMnktAmpc/g4E8i6WTC/9qmdzpEzEzJnw=; b=WuMaQFp5sZFsmy4YuFbuJNJPSDqN1niCszhSweCjMojYLiP+M0ffTpFuNL5gRpplgh WyZFtUoeiYB8pPfM/h8zrJmXkcWNKAHaCHNbodzqwC2rtdObmPOH2ItgCz2zSA72OHQ+ 1HLHAu736nnMchrorjYPpwVqO2X+6S4QCap6j9PF3/wxpq9UIiES2of2bTgCYvAMdJKY 5pThdl0tnCQtXGEw6shN2/8UKPIh1tLclATeZ/e2jfDEMY8+hTYGe1kIKKo07cZRXqL6 DSbIUHy9lJXrGa0kVvNu2RYIaWdTBicGXKpK5gnmad1atafbocZXGksrDykaVVuru6/z DcGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=nxHOtHkV; 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=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n22si14533345pfb.126.2018.05.03.21.09.23; Thu, 03 May 2018 21:09:39 -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=@umn.edu header.s=20160920 header.b=nxHOtHkV; 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=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750979AbeEDEJQ (ORCPT + 99 others); Fri, 4 May 2018 00:09:16 -0400 Received: from mta-p2.oit.umn.edu ([134.84.196.202]:50740 "EHLO mta-p2.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750707AbeEDEJO (ORCPT ); Fri, 4 May 2018 00:09:14 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p2.oit.umn.edu (Postfix) with ESMTP id A37605DE; Fri, 4 May 2018 04:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=umn.edu; h= content-type:content-type:subject:subject:message-id:date:date :from:from:references:in-reply-to:received:mime-version:received :received:received; s=20160920; t=1525406953; x=1527221354; bh=t lS28RgyOP/KJQn/f/32Hyun+TnGvXB8j3RBNQ3v2HI=; b=nxHOtHkVcSnpk00HQ T3MQ1Y+6S7arC4CT7LsnwPG5CzrTR7X0/e2ntzn5s649YQEDQ331AlsmO0pDFm1G FLJs3UhMHLsae4fFRphGq/I9/hksH4tU++GTTJOWP+QR/lA2WquWbgUgrzqZgvZY ++R34y3ij6HN33wZJ8JfF4zp2rmb7KxPccta1+LuI6/4rRtIzE/ZUHn1+6eM5nwN EcAXP39Lh060NWTF+l9glWJKIn9d+SoGZ9WazjkbL6GOQUwwBs6GqAZGF5P10xqj 0ayPgRUOLNzwl43FzTou0jGHnKAFeR4XUIj6vZf3UUR/arZuCYSrb/m0SURhwWAO KX2wA== X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p2.oit.umn.edu ([127.0.0.1]) by localhost (mta-p2.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kLuD-tLauzbh; Thu, 3 May 2018 23:09:13 -0500 (CDT) Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: wang6495) by mta-p2.oit.umn.edu (Postfix) with ESMTPSA id 7A8682FC; Thu, 3 May 2018 23:09:13 -0500 (CDT) Received: by mail-io0-f178.google.com with SMTP id e12-v6so24181699iob.8; Thu, 03 May 2018 21:09:13 -0700 (PDT) X-Gm-Message-State: ALQs6tBWmtu+F/4XlCBj5g3/S62SSaRw7kM+uI7TSuif9U+fOrEHn04h Qjd56+lNqub8jHgCEFV6gXILuQzLWs0xtg0zTn8= X-Received: by 2002:a6b:200e:: with SMTP id g14-v6mr29672563iog.161.1525406953200; Thu, 03 May 2018 21:09:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:6f07:0:0:0:0:0 with HTTP; Thu, 3 May 2018 21:08:32 -0700 (PDT) In-Reply-To: <4390a69e-a297-313d-044d-abf846eff1d1@axentia.se> References: <1525300581-27217-1-git-send-email-wang6495@umn.edu> <4390a69e-a297-313d-044d-abf846eff1d1@axentia.se> From: Wenwen Wang Date: Thu, 3 May 2018 23:08:32 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] i2c: core-smbus: fix a potential uninitialization bug To: Peter Rosin Cc: Kangjie Lu , Wolfram Sang , "open list:I2C SUBSYSTEM" , open list , Wenwen Wang 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 Thu, May 3, 2018 at 3:34 PM, Peter Rosin wrote: > On 2018-05-03 00:36, Wenwen Wang wrote: >> In i2c_smbus_xfer_emulated(), there are two buffers: msgbuf0 and msgbuf1, >> which are used to save a series of messages, as mentioned in the comment. >> According to the value of the variable "size", msgbuf0 is initialized to >> various values. In contrast, msgbuf1 is left uninitialized until the >> function i2c_transfer() is invoked. However, mgsbuf1 is not always >> initialized on all possible execution paths (implementation) of >> i2c_transfer(). Thus, it is possible that mgsbuf1 may still not be > > double negation here > >> uninitialized even after the invocation of the function i2c_transfer(). In >> the following execution, the uninitialized msgbuf1 will be used, such as >> for security checks. Since uninitialized values can be random and >> arbitrary, this will cause undefined behaviors or even check bypass. For >> example, it is expected that if the value of "size" is >> I2C_SMBUS_BLOCK_PROC_CALL, the value of data->block[0] should not be larger >> than I2C_SMBUS_BLOCK_MAX. But, at the end of i2c_smbus_xfer_emulated(), the >> value read from msgbuf1 is assigned to data->block[0], which can >> potentially lead to invalid block write size, as demonstrated in the error >> message. >> >> This patch simply initializes the buffer msgbuf1 with 0 to avoid undefined >> behaviors or security issues. >> >> Signed-off-by: Wenwen Wang >> --- >> drivers/i2c/i2c-core-smbus.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c >> index b5aec33..0fcca75 100644 >> --- a/drivers/i2c/i2c-core-smbus.c >> +++ b/drivers/i2c/i2c-core-smbus.c >> @@ -324,7 +324,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, >> * somewhat simpler. >> */ >> unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; >> - unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; >> + unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2] = {0}; > > I think this will result in the whole of msgbuf1 being filled with zeroes. > It might be cheaper to do this with code proper rather than with an > initializer? Thanks for your comment, Peter! How about using a memset() only when i2c_smbus_xfer_emulated() emulates reading commands, since msgbuf1 is used only in that case? Thanks, Wenwen > > Cheers, > Peter > >> int num = read_write == I2C_SMBUS_READ ? 2 : 1; >> int i; >> u8 partial_pec = 0; >> >