From patchwork Mon Jan 4 09:56:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 7946451 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EF4479F1CC for ; Mon, 4 Jan 2016 09:58:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0AE7820373 for ; Mon, 4 Jan 2016 09:58:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A9C620251 for ; Mon, 4 Jan 2016 09:58:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aG1sE-0004mp-Fu; Mon, 04 Jan 2016 09:56:22 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aG1sB-0004bx-JA for linux-arm-kernel@lists.infradead.org; Mon, 04 Jan 2016 09:56:20 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id ED818ABBF; Mon, 4 Jan 2016 09:55:54 +0000 (UTC) Received: by quack.suse.cz (Postfix, from userid 1000) id D2A81823D8; Mon, 4 Jan 2016 10:56:05 +0100 (CET) Date: Mon, 4 Jan 2016 10:56:05 +0100 From: Jan Kara To: Arnd Bergmann Subject: Re: [PATCH v2] udf: avoid uninitialized variable use Message-ID: <20160104095605.GC3888@quack.suse.cz> References: <9221187.T0u8gszVyj@wuerfel> <5491623.oZlI0zcRmi@wuerfel> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5491623.oZlI0zcRmi@wuerfel> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160104_015619_980391_78B32DC0 X-CRM114-Status: GOOD ( 25.58 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kara , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri 01-01-16 15:21:54, Arnd Bergmann wrote: > A new warning about a real bug has come up from a recent cleanup: > > fs/udf/inode.c: In function 'udf_setup_indirect_aext': > fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized] > > If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG, > the value of adsize is undefined. This changes the code to use zero for adsize > in that case, which may be the correct solution, though I have not looked > at the code in enough detail to know if it should be something else instead. > > Signed-off-by: Arnd Bergmann > Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent") > --- > sorry for missing another instance the first time around. The warning is > a bit unreliable and it seems in my first configuration I got it only > for one of the two instances that show it in other configuration. > > After checking the remaining functions in this file for the same possible > problem, I found that the other functions use either 'BUG()' or 'return -EIO' > in the 'else' path, so I assume the two functions here should one of those > as well, but I don't know which. Callers of these functions make sure alloc_type is one of the two valid ones. However for future-proofing you're right that probably we should handle the invalid case as well. Setting adsize to zero is problematic - not sure what the code would actually do but it wouldn't definitely work. I'd just return -EIO. Attached is the patch I have merged. Honza > > diff --git a/fs/udf/inode.c b/fs/udf/inode.c > index 5b83351041a4..42f68dd7e6ef 100644 > --- a/fs/udf/inode.c > +++ b/fs/udf/inode.c > @@ -1890,6 +1890,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block, > adsize = sizeof(struct short_ad); > else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG) > adsize = sizeof(struct long_ad); > + else > + adsize = 0; > > neloc.logicalBlockNum = block; > neloc.partitionReferenceNum = epos->block.partitionReferenceNum; > @@ -1963,6 +1965,8 @@ int __udf_add_aext(struct inode *inode, struct extent_position *epos, > adsize = sizeof(struct short_ad); > else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) > adsize = sizeof(struct long_ad); > + else > + adsize = 0; > > if (!epos->bh) { > WARN_ON(iinfo->i_lenAlloc != > From 4f1b1519f7bec44ded3c2c4d46a2594c01446dc8 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 1 Jan 2016 15:21:54 +0100 Subject: [PATCH] udf: avoid uninitialized variable use A new warning has come up from a recent cleanup: fs/udf/inode.c: In function 'udf_setup_indirect_aext': fs/udf/inode.c:1927:28: warning: 'adsize' may be used uninitialized in this function [-Wmaybe-uninitialized] If the alloc_type is neither ICBTAG_FLAG_AD_SHORT nor ICBTAG_FLAG_AD_LONG, the value of adsize is undefined. Currently, callers of these functions make sure alloc_type is one of the two valid ones but for future proofing make sure we handle the case of invalid alloc type as well. This changes the code to return -EIOin that case. Signed-off-by: Arnd Bergmann Fixes: fcea62babc81 ("udf: Factor out code for creating indirect extent") Signed-off-by: Jan Kara --- fs/udf/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 846294891925..91d8fa9d87a4 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -1889,6 +1889,8 @@ int udf_setup_indirect_aext(struct inode *inode, int block, adsize = sizeof(struct short_ad); else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG) adsize = sizeof(struct long_ad); + else + return -EIO; neloc.logicalBlockNum = block; neloc.partitionReferenceNum = epos->block.partitionReferenceNum; @@ -1962,6 +1964,8 @@ int __udf_add_aext(struct inode *inode, struct extent_position *epos, adsize = sizeof(struct short_ad); else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) adsize = sizeof(struct long_ad); + else + return -EIO; if (!epos->bh) { WARN_ON(iinfo->i_lenAlloc != -- 2.6.2