Received: by 10.192.165.148 with SMTP id m20csp1127436imm; Sat, 5 May 2018 05:26:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrSKxsMcN9jzHqOIFz0/wYJPNrPn807G3JnAGFQRyayLmhgZ0ARzfNbx/SFqnouw5XSjrg5 X-Received: by 10.98.219.5 with SMTP id f5mr30425151pfg.137.1525523195056; Sat, 05 May 2018 05:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525523195; cv=none; d=google.com; s=arc-20160816; b=W+32aYN7fo3l+G3j6sHsl7aA30YH3hbAnMH+cyu87s+gLkxIBaDAoNnphwOgnuiCK8 umh13VvwvvGVIQDixBuVTtpirHyQ1IGZek5lyyrQa3Q1FRm8yCdZxqOzb/yYyfTnD3LZ kNnJv3NoB2vCXuz4C1tDFtAz+xlIDZZSt62zTll2id4o2sNgbByrnSEImJlxss24DndW ncYWqNvNcJc46iMX0xJc8UvS8Glb10WK/GYGGyGlFqaifEprdfyqV71GJjsUNrXvErip T98aanyyBnYyVUBXOdbX2riGZsc+8t/vAVj78KfK9BIWoHcwLpvyfbHAfvKbKdCL2ga0 vz4g== 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=BzfA77aNPy5+mcAipnOz2+ciKD1LBfLYE7nm41IGE3I=; b=V++BuTjc9QkjKQL4YMdSCMRVkO99mwXOv5yzt47y987dtjRhiO5eST2z1+u1O3zCvg K3S2Q3NmN0OB7tDNyA4X3NZTBKm72oYxZvQLzjOw3bXZ72b8LrxQM2yvRnM2/PWA8AUZ 6aSP+Cneeyiju3/WHyrQ0vwdWT1QbIp9MMkeTzvl6Inpo5zmTwpj+I9OyUg3B6drfUGY shSAcIIZ+W+za8SWOSTnIVB6frpdoKyHcSuozuy57DhGvoY23u99S2mMMJFFOUgFdFAH 383lShYwBVfBJSgvkXdInPzG9+wfY8YHWJ0jb4DZcNaPnM7tZMFqzr+gEwnB6K30YB8w BR3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=ZAKlt04O; 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 t185-v6si14565978pgd.487.2018.05.05.05.26.07; Sat, 05 May 2018 05:26:35 -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=ZAKlt04O; 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 S1751230AbeEEMZz (ORCPT + 99 others); Sat, 5 May 2018 08:25:55 -0400 Received: from mta-p4.oit.umn.edu ([134.84.196.204]:55274 "EHLO mta-p4.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086AbeEEMZx (ORCPT ); Sat, 5 May 2018 08:25:53 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p4.oit.umn.edu (Postfix) with ESMTP id 9AEB469B; Sat, 5 May 2018 12:25:52 +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=1525523152; x=1527337553; bh=B bwxna558y582huFIhJZTrIpGes2U5ZSSj1e7DIN/7w=; b=ZAKlt04OZvyqsdhcf Cg6mBeL8OJ4MqM+Yrdg/WInHogcUliCJoWnAONp91Ju55ybAi48zW3GdvdZOeFlv p6MjBVBRUwDGRlUEtsF+Oh4ygGd/TE1VUqwUc5BZcfyFxhxZ5/Q2A783Asug1E6x lNUep0lTFjsLcIRXUppjZreH4kRfWVBh2q/WtsxzzYVGJ/ehMNJtMul5MMaIZ6Et oesUOi6Y/qdK6Y4vM5898mAuTyyUTgrWXSsf0wswH1qsfxfmG47j80hN1tRoULxq o3Xj9Flu2IXNYGDI4OfbeYeRagS3s5A8G99bW/R7LVhqBwj/IHMtvajeiR5fv3B+ y7ZvA== 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 mgu2raS2asBi; Sat, 5 May 2018 07:25:52 -0500 (CDT) Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) (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 7731B149; Sat, 5 May 2018 07:25:52 -0500 (CDT) Received: by mail-io0-f177.google.com with SMTP id d11-v6so28601472iof.11; Sat, 05 May 2018 05:25:52 -0700 (PDT) X-Gm-Message-State: ALQs6tDYdg1uuhqiz7lImejXm84rzoWpXU7rm2tC/MZF/OHZHAZxLevQ Y83e84ts0r3DuGAnwAZ4y+BQboAXXAusOhAvPds= X-Received: by 2002:a6b:b806:: with SMTP id i6-v6mr33005209iof.21.1525522689392; Sat, 05 May 2018 05:18:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:6f07:0:0:0:0:0 with HTTP; Sat, 5 May 2018 05:17:29 -0700 (PDT) In-Reply-To: <63ff0aae-9a34-9c6a-625d-7b07b7da9ed3@axentia.se> References: <1525484596-5585-1-git-send-email-wang6495@umn.edu> <63ff0aae-9a34-9c6a-625d-7b07b7da9ed3@axentia.se> From: Wenwen Wang Date: Sat, 5 May 2018 07:17:29 -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 Sat, May 5, 2018 at 5:28 AM, Peter Rosin wrote: > On 2018-05-05 03:43, 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 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 checks the return value of i2c_transfer() and also initializes >> the first byte of msgbuf1 with 0 to avoid undefined behaviors or security >> issues. >> >> Signed-off-by: Wenwen Wang >> --- >> drivers/i2c/i2c-core-smbus.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c >> index b5aec33..e8470d5 100644 >> --- a/drivers/i2c/i2c-core-smbus.c >> +++ b/drivers/i2c/i2c-core-smbus.c >> @@ -344,6 +344,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, >> }; >> >> msgbuf0[0] = command; >> + msgbug1[0] = 0; >> switch (size) { >> case I2C_SMBUS_QUICK: >> msg[0].len = 0; >> @@ -466,6 +467,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, >> status = i2c_transfer(adapter, msg, num); >> if (status < 0) >> return status; >> + if (status != num) >> + return -EIO; >> >> /* Check PEC if last message is a read */ >> if (i && (msg[num-1].flags & I2C_M_RD)) { >> > > I think these two hunks should be two separate patches. They address > orthogonal issues... Sure, I will split it into two patches and fix the typo :) Thanks! Wenwen