Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2924771rdh; Wed, 27 Sep 2023 18:13:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuqEB3/GdsZw5ZSALVhaQPh6IMKYbhhaB9rHcVqGFI8FIAgzh8VWr4O9lixffzjv4zOj0c X-Received: by 2002:a17:902:6b0a:b0:1c5:6f4d:d6dd with SMTP id o10-20020a1709026b0a00b001c56f4dd6ddmr9756775plk.24.1695863580234; Wed, 27 Sep 2023 18:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695863580; cv=none; d=google.com; s=arc-20160816; b=bPkKXPj0QpQDDF3YTNbG/o/O6Cmku9hGTldAYZuREWaRahGw0NScUpAv6F7V2/6UZg EyYySqAiT6VYy9T0dbQky1v6Q8D/NNKQFdfCYUU6wE/e14ia+9p5wB2q952xuF+6J24I /3+wtwFr613+vKHkMSasQiyrNw5yotP57fwabR9Zvnq7XTae/GwHExqMVLzUGwi6Yfhb CAOf0Gjfm/AH6qDFjzPB4WrfcEk8dqHkrav29glyrzxJSFrTOenhSkqumoPgCmeXH93l 7YqO+aAeYJ4+cS2xEWrIa7Uc/NJZmKnnNvWfB9LXHrFFO4tdqE1TYlBAb1RPeu4wap8j Lrtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc:to :content-language:subject:user-agent:mime-version:date:message-id; bh=9uNwPSz8/mDkuDzqC77a+tpI2YFcpdT7basURmi7AlA=; fh=U0ztPglofeBxS/PtmNX4T3245PZK0VbanT+/cP1OBow=; b=c7pBldAUjJDMwWdLWrpw9k1gx5C8iZClSsnS7kcF5fsDf+L/60nvsovP4MoLnKEUjJ oGox6C6ehx4ZsVolEtAzR5Qm8cygB2tVjuZF6wK7WrDl882s/cCLtfye6N5zAoC9XzEw wze92JQDjRuvhZPqP0dD0oQ6U84uivoKFnl3SvkRIE4Qh1IrhuTArbQapqaOM7L+PfIQ maM/uPUs2a8jbBA81cn754VSK9jY8TvCPHRFhphMPjOpxkdw7B+dQsodpSr7z/VCt/b3 k/5Rj7jCYoqfq+bLwJUWP47W1w9T0gmowwhsB7E8rGN/BYA3vgv1TzoFEXQfLoH1vv6V 6zGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id r1-20020a170902c60100b001c6223663b2si7566797plr.339.2023.09.27.18.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 18:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7D3D781A9EF9; Wed, 27 Sep 2023 18:12:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjI1BMJ (ORCPT + 99 others); Wed, 27 Sep 2023 21:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjI1BMI (ORCPT ); Wed, 27 Sep 2023 21:12:08 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id B1983BF; Wed, 27 Sep 2023 18:12:05 -0700 (PDT) Received: from [172.30.11.106] (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id 4ADCF6018F7FD; Thu, 28 Sep 2023 09:12:02 +0800 (CST) Message-ID: Date: Thu, 28 Sep 2023 09:12:01 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] ovl: avoid possible NULL dereference Content-Language: en-US To: Dan Carpenter , Amir Goldstein Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 18:12:40 -0700 (PDT) On 2023/9/27 22:39, Dan Carpenter wrote: > On Wed, Sep 27, 2023 at 05:02:26PM +0300, Amir Goldstein wrote: >> On Mon, Sep 25, 2023 at 7:52 AM Su Hui wrote: >>> smatch warn: >>> fs/overlayfs/copy_up.c:450 ovl_set_origin() warn: >>> variable dereferenced before check 'fh' (see line 449) >>> >>> If 'fh' is NULL, passing NULL instead of 'fh->buf'. >>> >>> Signed-off-by: Su Hui >>> --- >>> fs/overlayfs/copy_up.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c >>> index d1761ec5866a..086f9176b4d4 100644 >>> --- a/fs/overlayfs/copy_up.c >>> +++ b/fs/overlayfs/copy_up.c >>> @@ -446,7 +446,7 @@ int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower, >>> /* >>> * Do not fail when upper doesn't support xattrs. >>> */ >>> - err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf, >>> + err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh ? fh->buf : NULL, >>> fh ? fh->fb.len : 0, 0); >>> kfree(fh); >>> >>> -- >>> 2.30.2 >> After discussing this with Dan Carpenter, this is not a kernel bug, >> it is a smatch bug. > Yeah. Sorry about that, Su Hui. The ->buf struct member is not a > pointer, it's an array. So this isn't really a dereference, it's just > pointer math and foo = fh->buf won't crash even if fh is NULL. Got it, I'm so careless that make this wrong patch. Really thanks for your reminder! Su Hui > > I have written a fix for this in Smatch. I'll test it a bit before I > push it. > > regards, > dan carpenter >