Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2683663rdh; Wed, 27 Sep 2023 09:32:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5NF8RlIefw+MvK3+MDynJnWg3I23Sn7UO5BRn+b7hH2t4VJzQpYaao0ba3oPGt/c69MVM X-Received: by 2002:a17:90b:283:b0:274:7725:ed9c with SMTP id az3-20020a17090b028300b002747725ed9cmr2159864pjb.35.1695832364759; Wed, 27 Sep 2023 09:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695832364; cv=none; d=google.com; s=arc-20160816; b=hKwIAI9Gdd81KvYOClLkA1+NtFZPx1hkyPKYUrtw0abqsh0DBGtHRdYcLOF45HUBxl 0jBGaf6iLBvo6OeV9M3Mj+8fGrOaeoa/stNA86/QFIQXwbNC4NsEkip5IoqgqkdFsehX Gzp+LdbycL/DbY7AxwzliC/03AV0y9xn4oYyvDqSQLsLwzEXqLNsJTgm0o9V8GwBNJIE q3bm3kR3f6MFjSmMl1q9w7EoZEpu2EWNbJZlOaoS+VLYwrj0aOC8HUzm3tsb/zLVs8uM H9zl8hOrDNaCtGz218P3OzG6h/5d6Dze5g5b1OWaPon3vAh4Ass5c0dlWaMsMS8Xi+zW ZpOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZBgo/SWIO02Pm/xzDvMlyzJPp7I0czV8f3hR93KFgsk=; fh=F62gFChhxElxanW41Tp2hRl4OxfW8xpVDSeJ/LkBEoQ=; b=SvQBzD7pOqCwhgq1YVux1e3HZx5uBJR6lem7eN5zdewKVsT1mMxVe2C1pE355oq33f Bj8MbsSN/6hv4ECC4V5khxck8+0wXieGTd/nQ2LRVAtqXnu6jP8MnXs4TMJ0+sJIU31E 9lFMbkoAtOiQhcBCP9UCUZkY7wCBXX836tvv7aE1c94WmsmdjT8mqkMjH48dUr9WqJo6 cN3Blh/T18RrQor4P2ipo1dPOQMolL1HipkwQmE1zHwXOtA9lByTwhe9Nfq6KHMTXV0q z55dRHWkVKyabs9HWV4OgqKxZVWtrr4vCBowAIAWWx/IBZ9ZN1EvEbhKEISKEicz7yG0 UgOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R2ULERYd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id mp22-20020a17090b191600b0026d4e16c957si17903742pjb.77.2023.09.27.09.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 09:32:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R2ULERYd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0621D81F4725; Wed, 27 Sep 2023 07:02:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbjI0OCl (ORCPT + 99 others); Wed, 27 Sep 2023 10:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjI0OCj (ORCPT ); Wed, 27 Sep 2023 10:02:39 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C54610A; Wed, 27 Sep 2023 07:02:38 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6c4c594c0eeso5491405a34.0; Wed, 27 Sep 2023 07:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695823357; x=1696428157; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZBgo/SWIO02Pm/xzDvMlyzJPp7I0czV8f3hR93KFgsk=; b=R2ULERYdMlfhBMmUAbH1iL3UJpsD6DYE3a157LM7ogB3chQ3KEJXolTPGf/PUdx3Yw oY38XQmN+FoaUjkr9PAdOXxr3aKzjRXW1YfIWaBkSNrT0kk/4QFzAUYWNjSBEecjWxzR f5ZIRVPbHab22Z4+1Krc0sNM6mupDKkp+dMUmG44zEX7HnpqQOup5qT3pEzOozkhiHFt XDFtnWOc0LrkdH3QPmbA7FLsX219gNsYooe+y6tXI6JPpIZ5usPIc45/kX/rSBGPwujX MFBGJjOmN0oSsJQ2F9GL6HNNmTjjtBTLFTW46w8AU1uRnquc4CxOAiJD9vtl8C/qSIqI I7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695823357; x=1696428157; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZBgo/SWIO02Pm/xzDvMlyzJPp7I0czV8f3hR93KFgsk=; b=oIQLTmKlp7uGnrUsikcGCiGOscIc06pXOcTBof0WR0DwvEJKRhsNJqv1oh1qKcrI6g k65H3xxEhW79APbg9c8ZkfpmsWZKg2XgKYt/tRAnm0W+dvsyvZRAL53Cl5DA8rctXCuf R7vV9KtaTauaFLC9Ep0/ejFuzymeoLnq2gDQlZYewFD32H1q9WIBb1qhVyZ5AR86bw1v wOkMUjCgTgKbj4QykoaXbkqUxaz7KQviB81CMxhTQ9KOCSKo6+ALMdAVTz52sgUG0o6N NQaDkdRFBqrJyzbb6SHSktiDQG3iQHmqwH65HjNje15s3zjPqkYMAsLNEcLB284pC40e Ol+Q== X-Gm-Message-State: AOJu0YyhzzuSU8qH4T6Vpa2FeKB/DZ9w/wZ1ul6LFBWSjLavAIMZ1zhl 4pq6eL0S2hkSTv8J+XLvDZrlrbU8V9z33oXIhQo= X-Received: by 2002:a05:6358:6f08:b0:142:d097:3725 with SMTP id r8-20020a0563586f0800b00142d0973725mr1931059rwn.9.1695823357416; Wed, 27 Sep 2023 07:02:37 -0700 (PDT) MIME-Version: 1.0 References: <20230925045059.92883-1-suhui@nfschina.com> In-Reply-To: <20230925045059.92883-1-suhui@nfschina.com> From: Amir Goldstein Date: Wed, 27 Sep 2023 17:02:26 +0300 Message-ID: Subject: Re: [PATCH] ovl: avoid possible NULL dereference To: Su Hui Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Dan Carpenter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 07:02:58 -0700 (PDT) On Mon, Sep 25, 2023 at 7:52=E2=80=AFAM 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 =3D ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf, > + err =3D 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. The value being passed to setxattr is (void *)OVL_FH_FID_OFFSET, which is just as arbitrary as NULL when size is 0. Thanks, Amir.