Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4890881imm; Fri, 18 May 2018 12:27:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8YGHWNC8Ut3wBTvmN/aVAxOObgvCnFWE4Tgbb/813aFiZd/D497LInBBg6eAujwCw3z82 X-Received: by 2002:a62:3cd1:: with SMTP id b78-v6mr10493322pfk.44.1526671636869; Fri, 18 May 2018 12:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526671636; cv=none; d=google.com; s=arc-20160816; b=npgSU5Q5IMwhf0xZMv84OnE/MIz4cL4jTKgVkd/xhL5w4RT4YMx97LPkC3Lwgcfyny cHhpJKPicw6+ev+pGMDKwl5UMSUJDOHk2SgzqTLGJo/K7r9Tn0qQC9nhekaktIcKaLDH KL2sv3DFnojdJD7k2cu1hniHkyGD/c8bH9ZV0oKv4JMRgf5UVyb8WjsLFhA/87tC5J1f y6D8+v4f8/2aIqmt/l9jYddsj80cgUeXUW1N9S7ONyWZ8zFwc6V6P2TsbaO85FX2fUMM HajEvIMCAMLPfs+l8oSL02gQRGxYnhLao2Q6zoTY2ABz4CQmLaQ5f+1Sx5vZza04cgzN Fq7g== 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=u7xw+/7i6Fumt/ZV324b11dvk3YP/2TwV1VxN8WwzSQ=; b=aMppjIoxuhD7Q/DI1/bfJ9eSbt/yn6n4DfM2yPiYK7OPZjEdW1cpUNJ4MRuTpIDJN8 YbnUVZYk5jD9mS//QF1U3sDq8qwwActOgK6CwjMU5P7ubEL6c9K/MUQ/y+Pz3LfE93qL B2HMm0GmLWLbCebSIE16E/ZcjwjebMYeU1yw31dBrKFvUc50ax9EENONwfjrAHLfe8LH VOVTzCwkp6MuHV0IDEQPvhklZbvcI8Esb/+TjwBPC2Mo5ia1xnN8LcdR/wfmclWc8nsQ DIw6Tl0BEG36B7Ih5i8mxWGuSYKTZThL0qy8xOfb50prtBjaCtB6weitLPX/+T++7DLq cu0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=f2wpxTJd; 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 e9-v6si7787788pln.72.2018.05.18.12.27.02; Fri, 18 May 2018 12:27:16 -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=f2wpxTJd; 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 S1752240AbeERT0e (ORCPT + 99 others); Fri, 18 May 2018 15:26:34 -0400 Received: from mta-p4.oit.umn.edu ([134.84.196.204]:33170 "EHLO mta-p4.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750957AbeERT0a (ORCPT ); Fri, 18 May 2018 15:26:30 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p4.oit.umn.edu (Postfix) with ESMTP id B4CCD995; Fri, 18 May 2018 19:26:29 +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=1526671589; x=1528485990; bh=u 7xw+/7i6Fumt/ZV324b11dvk3YP/2TwV1VxN8WwzSQ=; b=f2wpxTJdk0RyH7l9a H/nKlann0lascKmHNhH10R/UIe315Xqp/0l4d0etJe2S75Z01Lhet5euZ0uANLEF CsaG8C9pTai3NJmTk37UZaZC9jxyrzjS1mpCuhM6oQj8OgBmFpG9NwmIohvu5IbP aJ4vcJwQQxje1ji9z9Bm5CfZoEINEmq1kRDKZWZs0C3DLSYERXZrZsXPFDbUL3Zn zFUs9hIBTVSZVtBEB7pQgLL7g/yLtm4oUaLamuINSoSUB9hGOU3lkV3ty2owv9+D 1A/YEkuU9SILP3ZZFz3LGmNQsUmBP4yIuoZZ/4Og9wCSQtBS5GHrtBFCbWhfmtab dMM+Q== X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p4.oit.umn.edu ([127.0.0.1]) by localhost (mta-p4.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aZ7QQyNod4p2; Fri, 18 May 2018 14:26:29 -0500 (CDT) Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: wang6495) by mta-p4.oit.umn.edu (Postfix) with ESMTPSA id 8E362712; Fri, 18 May 2018 14:26:29 -0500 (CDT) Received: by mail-io0-f175.google.com with SMTP id d11-v6so7479574iof.11; Fri, 18 May 2018 12:26:29 -0700 (PDT) X-Gm-Message-State: ALKqPweiApzIx5pn917W3PNsSNIr+QBqlQC+EMSUCHDSfEiKU3sonf7E EYHqFAUOYx4UFJgM8U4doboMSn+OzxZ1+fL70sc= X-Received: by 2002:a6b:b806:: with SMTP id i6-v6mr11764265iof.21.1526671589329; Fri, 18 May 2018 12:26:29 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:9850:0:0:0:0:0 with HTTP; Fri, 18 May 2018 12:25:48 -0700 (PDT) In-Reply-To: References: <1525525030-9805-1-git-send-email-wang6495@umn.edu> <20180510111737.b6g7s2nnf6froote@ninjato> From: Wenwen Wang Date: Fri, 18 May 2018 14:25:48 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] i2c: core-smbus: fix a potential uninitialization bug To: Wolfram Sang Cc: Peter Rosin , Kangjie Lu , "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 Yes, this patch does not aim to "fix" all potential driver bugs but adds an additional protection in case the implementation of .master_xfer is incorrect. From this perspective, it is still necessary to apply this patch, as pointed out by Peter. Thanks, Wenwen On Mon, May 14, 2018 at 3:31 PM, Peter Rosin wrote: > On 2018-05-10 13:17, Wolfram Sang wrote: >> On Sat, May 05, 2018 at 07:57:10AM -0500, 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, msgbuf1 is not always >>> initialized on all possible execution paths (implementation) of >>> i2c_transfer(). Thus, it is possible that msgbuf1 may still be >>> uninitialized even after the invocation of the function i2c_transfer(), >>> especially when the return value of ic2_transfer() is not checked properly. >>> 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 initializes the first byte of msgbuf1 with 0 to avoid such >>> undefined behaviors or security issues. >>> >>> Signed-off-by: Wenwen Wang >> >> From what I can tell, this patch is not needed anymore after patch 2 is >> applied. Correct? > > AFAIU, it is only needed if there are bugs elsewhere. I.e. it's for extra > protection. If all drivers implement .master_xfer correctly, msgbuf1 will > be filled in and the return value will be the number of messages (i.e. 2) > OR you get a negative return value and the msgbuf1 content will not matter. > > The patch does not magically fix all possible driver bugs, so in that > sense this patch is still "needed". > > Also - again AFAIU - there is no known bug that actually gets caught by > this extra check. > > Cheers, > Peter