Received: by 10.192.165.148 with SMTP id m20csp427556imm; Thu, 3 May 2018 23:50:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqwvH83RtVxFTrCx34IRSzbBVXwFEy+bHD3WywwWUqN2wwRmRThCxVO0JJxbPprjeSYSpyM X-Received: by 2002:a17:902:5709:: with SMTP id k9-v6mr26091069pli.165.1525416620416; Thu, 03 May 2018 23:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525416620; cv=none; d=google.com; s=arc-20160816; b=BXdxAx2fl3cFXlJT34snZFH5TY54lbcw4sw5VRjVDEP64TUC2qmrioE+Dftehxtjlx +7oNiiJ8Hkz08aQpQtMzVZPjAOZR6+b5eQ994warooFfeg6jtdxBA4hHudsQTR2tOqXa 9u5ORmA9El3YRqA5D7gGQFUKAfzJRz4EItHQPiy4QTLbwDDB+4cLZK1oLECtTNuNGiXB hrgWpJcCY99it+8Ib1UG4NEHdYDiQX+7jksPzQ0dXoxKEbPVppBpLXQwwcZeBcXCdwR4 ExkPVHW8HogQytCzRjGByjV0x0Iznb8jHjw7x3nM9IJ992vl3CyRLcdiF7cCtEd5LF1E 0Uag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=J3TkJRHBmeW7U49FuwwmM4LRTEe7sCCS9I/c1aWcuK0=; b=YjH5WXYy/e6jxjnWAuIPn+/fVhOairta+L4i8YqNk0PnZXhfH5LVG21x47qGbsPbo1 gXKxfWXgB+NspsNwJWTYaY2RZ/TrNBKDmsRXOC376NlyOgxS+x1xchmIFmoPHkKb4smE qNt8cIBDSXWMtrne9G96t0Duy+nZTPunIRn9OKwKe9TQtDfjsxCgMtRZdN1XyNk4GJIK bykNSNjG1oF8olvuwDT+Q8aLk//wee9ptY0SVKwYcayJMzvwLvc4UMGPHnKc9Bo5MOnL RBEue0NY93rAUNPoenEBNeZeQhKzZ05J+hCFhTqmExiCvlw6CyHZ75U1evZkeQaA5jHH uevA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axentia.se header.s=selector1 header.b=LVe+6hIR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si1334543pfe.367.2018.05.03.23.50.06; Thu, 03 May 2018 23:50:20 -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=@axentia.se header.s=selector1 header.b=LVe+6hIR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751269AbeEDGto (ORCPT + 99 others); Fri, 4 May 2018 02:49:44 -0400 Received: from mail-he1eur01on0111.outbound.protection.outlook.com ([104.47.0.111]:55841 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750709AbeEDGtl (ORCPT ); Fri, 4 May 2018 02:49:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentia.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=J3TkJRHBmeW7U49FuwwmM4LRTEe7sCCS9I/c1aWcuK0=; b=LVe+6hIR0/II77Odf/+5vRAjWuPs1hAuhh6CVbamN5B8bbboWp3QyFBQXmPByQeptGg2gnc3J/HOvBYqr6wIeG4FUOuygqDmWkeVq1mowZfnh5x3EQgutb4XvSb4MvPeNRHIF/+iVPxD1Ms5V0Xa34/kZiuwQJmnvCjDKLMxurA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Received: from [192.168.13.3] (85.226.244.23) by HE1PR0202MB2779.eurprd02.prod.outlook.com (2603:10a6:3:e8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.715.22; Fri, 4 May 2018 06:49:33 +0000 Subject: Re: [PATCH] i2c: core-smbus: fix a potential uninitialization bug To: Wenwen Wang Cc: Kangjie Lu , Wolfram Sang , "open list:I2C SUBSYSTEM" , open list References: <1525300581-27217-1-git-send-email-wang6495@umn.edu> <4390a69e-a297-313d-044d-abf846eff1d1@axentia.se> <82973b7b-b6ef-6d42-df5c-be3ea72212fa@axentia.se> From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Fri, 4 May 2018 08:49:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [85.226.244.23] X-ClientProxiedBy: HE1PR05CA0221.eurprd05.prod.outlook.com (2603:10a6:3:fa::21) To HE1PR0202MB2779.eurprd02.prod.outlook.com (2603:10a6:3:e8::21) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(7021125)(5600026)(4534165)(7022125)(4603075)(4627221)(201702281549075)(7048125)(7024125)(7027125)(7028125)(7023125)(2017052603328)(7153060)(7193020);SRVR:HE1PR0202MB2779; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0202MB2779;3:FPfEtESKxKLO3jYDFwdWCebpIzQUojf/nlOI9fjE/pGo9pxXnPspeMyYaHYL0f2vQ49GwKgn9Me1ee6Cc/g/pjlQ4JIzbMXEaUIdm7/BboRzDH3hfkqfGrepqeqWCnIMwdEgKL/vlryJNfo+7O74CQnoRgR0BvpwdmKff2xpDitx7GT9FSO6vjd3HDMtYtIolSBGfd+u9rZpaZAR/URCBm/8wcCAEP3H/gfoYVUAGq1hxvT8hxo68p38CFytnFLW;25:KRFvjrPFR2z+l7xfiaue20A2YkoGD9w2NJpQ08iUoqy/t8KUhPBtoL+VR31RPhDdMk9jTDipHg9UHkTlCJ7w0X3h9dus+wTtHrnGMIM5A35ilHiYf+/vc6Br6N3RiWdVcfHk+c/Jrq2twkWDjiJcWaBd4yT7iVw6IH5Crq2mkQsmPKDF+RKBKBCeFt/wH/vCrzEYDYrBpKk48eBb3vLcHt0i6vyWmwSP01XvH6u+jbVz9fhJCcWF8a7vCHo5laeZr0FFCivB4FnEuT7dtRSBr/RpzHk+FZLAlsG0OQaBU42IzERKQd33OzcxEnDZVM2pwv4ZNzEIk5PTU7P/iCZbcQ==;31:LLIomtSpVqAqsZwNcklK4GbnkVFaPfHPREBfpnUqxzR7Bz+S5QqUbrHhcQDXQkJUSw2bKplOTN2crPYKVWmlFTouyEB6GADflATL0ikxNg7XBlMkGZ0aPznILespwijvdiFWXuFWe86PXZGZGvCYPgI0QU53I/bp8Bbud7/CJKsI6iABf69C1gHCdaOagGYckgZLbD5OsxpvuPK8AmT1XndfAoX12BYtb392VuHCVQw= X-MS-TrafficTypeDiagnostic: HE1PR0202MB2779: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(8104003914727); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(6041310)(20161123558120)(20161123564045)(20161123560045)(2016111802025)(20161123562045)(6043046)(6072148)(201708071742011);SRVR:HE1PR0202MB2779;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0202MB2779; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0202MB2779;4:NYZ1+XFslVT4V4B7d1kJgCWTeK3sI2DxYs++GgHvDky0NvP41E9wqb6TdnoeAsec0tc6qVAK9YCvHAmMnnK7Tk/EV5rkqHTHFvPV/z6erSdcoIJQpKFQmsT+laxFCMFsFj+KAJZebhpw6Src16d+5JH/DVhTshaVSpC4EAu0CQ4UL3mNTiKiHq1mSyLVE/JkY3nta3wqEddD9RUaRod2xdo4XV51e3ifVmuMdBSoqyR1nCynnUR+dpJpbbgpVnPOQlbj50LI8rZl1M32DFgFwo+guJ7F+lZF5a10wNntSopew8m+l79rRZJed4jgiTfxabfa2ZY0vjyZuzBtSiz4/+S05hPS8iSt3C+4dI5p1nE= X-Forefront-PRVS: 06628F7CA4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(376002)(366004)(396003)(346002)(39380400002)(39830400003)(199004)(377424004)(189003)(36756003)(68736007)(7736002)(54906003)(2616005)(2486003)(8676002)(2171002)(76176011)(6246003)(23676004)(36916002)(59450400001)(8936002)(52116002)(4326008)(386003)(81166006)(50466002)(53546011)(52146003)(26005)(81156014)(230700001)(16526019)(446003)(64126003)(3846002)(486006)(476003)(65956001)(77096007)(956004)(11346002)(6116002)(47776003)(65806001)(65826007)(186003)(66066001)(6486002)(117156002)(305945005)(31686004)(229853002)(53936002)(105586002)(106356001)(6916009)(5660300001)(86362001)(74482002)(478600001)(16576012)(2906002)(58126008)(3260700006)(97736004)(25786009)(316002)(93886005)(31696002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0202MB2779;H:[192.168.13.3];FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjAyMDJNQjI3Nzk7MjM6QVBxTWljUnQraGJ6NjhQS1hZNmY0bDhR?= =?utf-8?B?RUpWNXhmSnEwRlI2aXlsTWhBc3RrNE9ORXNFSWRUNk1UWWhrTDNDUUw1dVk4?= =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6izC2Qk+ZeynMA==;5:Qj6wz+Btcu2n/rHVci8QKdhY7Ma4SpkPw5YrOLGIgXjl7Pr1zxyenC3EglD7/lk+yZzPyC+6JACQA761JFUpUpjWDk1T/5iFyC/06COD3WyPdzeuonuv0DaqUoUI/D6PC44eEa3oBrTEI7ZdpIwuvVq4Ia8YyLPGTNnQ7p1ajMU=;24:J4+38dfUJcw6SyWlw+hy3YzvnWEq0GG0dXQY5r9ilNJ6ZuJUR3RHyjYhJWkhgk3XpI8DkYJcUFwSrlLDI5MhrxyuHUBpDvrVqZHMv27pTgI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0202MB2779;7:2H2ikMHfBJvIdlD+6SOku0GjoMD2B88iOHB6zRoNGuOmgzqQcBRB1KbZo7GHo78ZJrHKZH0OvWSYEIkIkjewDhwRh/DUtz6RjUn6RDHFXdYDCPRn4sG3BKmgLne4D4F6TMvmXzPy1zmWbhr0v3b+HfTK8Szo5IYSOsNqFYwIdoKG/ibosomYH8jk9YJvmQAfEstWEio2th8Vla2zaCMdeoM/cXX+sjhaUyPuwX8Ya7VuJGiDjvoLelQtmhqb8W4g X-MS-Office365-Filtering-Correlation-Id: 50917cd0-a470-4743-6ed1-08d5b18b320d X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2018 06:49:33.9229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50917cd0-a470-4743-6ed1-08d5b18b320d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0202MB2779 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-04 07:28, Wenwen Wang wrote: > On Fri, May 4, 2018 at 12:04 AM, Peter Rosin wrote: >> On 2018-05-04 06:08, Wenwen Wang wrote: >>> 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? >> >> I was thinking that an assignment of >> >> msgbuf1[0] = 0; >> >> would be enough in the I2C_SMBUS_BLOCK_DATA and I2C_SMBUS_BLOCK_PROC_CALL >> cases before the i2c_transfer call. However, this will only kick in if >> the call to kzalloc fails (and it most likely will not) in the call to the >> i2c_smbus_try_get_dmabuf helper. So, this thing that you are trying to fix >> seems like a non-issue to me. >> >> However, while looking I think the bigger problem with that function is that >> it considers all non-negative return values from i2c_transfer as good. >> IMHO, it should barf on any return values <> num. Or at the very least >> describe why a partial result is considered OK... >> >> Cheers, >> Peter >> >>>> >>>> Cheers, >>>> Peter >>>> >>>>> int num = read_write == I2C_SMBUS_READ ? 2 : 1; >>>>> int i; >>>>> u8 partial_pec = 0; >>>>> >>>> >> > > Yes, it is a big issue if the return value from i2c_transfer() is not > equal to num. I can add a check like this: > > if (status != num) > return -EINVAL; > Right, but make sure to add it *after* the existing "if (status < 0)" check as we want to preserve any existing error. Also, -EIO is perhaps more appropriate than -EINVAL which seems wrong for what is probably a runtime incident. > Also, I wonder why msgbuf1 is necessary if it is replaced by kzalloc > in i2c_smbus_try_get_dmabuf()? It is not always replaced. The stack buffer is probably retained as the default mode of operation (and fallback) because kzalloc is expensive and because kzalloc might fail? Cheers, Peter > Thanks, > Wenwen >