From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE19524501B for ; Tue, 6 Jan 2026 03:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767669065; cv=none; b=kejtD1qkOVgjJNspAVXJhgnGkDTCmU3uJI5SvSnQ+wCrQENeXQ/Nc9mxFmwdn/jFS1n4xeWdTJ8Bpo86gB9ofPhdLV016YwHbcVs9aNPID7is495QnxQNCW42mSJO8pp5tx8au8VipIi/XUmV4ukcBtcbC06Im6MRvja2P3MV0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767669065; c=relaxed/simple; bh=bpj4jEm2Ti2FL9FTE7AdFUlIB4PgMlx3TYrvoVVp4jY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lYvRLs0izu+8Het6bsynUC17PrJ9Puquzm6B5erYk5ouvVBi+YFj+jzD52qXaJiWM8abSEKXd4i1Smsibd+ZbfsequFsxzq5KgILCSjdZe2aQ1QSrgX6pLFUITkspiKESO/QoSfaRP3usgYrVjfyGxdxtE0+Leb3EdAOaKflba8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ZezAGxI1; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ZezAGxI1" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1767669059; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=42pAs3+fIQYhuJ9SLWC+Fz0cYorrswLXs6TEhqtdXBY=; b=ZezAGxI19CH66gvAl2tEQgxz21RLmPy3MvXtJvWP+4CM2OCeC7CLQDfuD4qqz4GmAQp4Q4E0loqFyVzOzKTUiItrx8tGH5rHsLpRCc6I5Ql2/lalLjnrDZIW0W8iD+/H9SjGlcarcGbGWfjeJOIkgQ6dnwbwLSIebzQJA4mwLTU= Received: from 30.221.131.80(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WwUFXOR_1767669057 cluster:ay36) by smtp.aliyun-inc.com; Tue, 06 Jan 2026 11:10:58 +0800 Message-ID: <3a0b7e98-5578-48f8-bcf2-8711a99adbc7@linux.alibaba.com> Date: Tue, 6 Jan 2026 11:10:57 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] erofs: Fix state inconsistency when updating fsid/domain_id To: Baolin Liu , xiang@kernel.org, chao@kernel.org Cc: zbestahu@gmail.com, jefflexu@linux.alibaba.com, dhavale@google.com, lihongbo22@huawei.com, guochunhai@vivo.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Baolin Liu References: <20260106025502.133470-1-liubaolin12138@163.com> From: Gao Xiang In-Reply-To: <20260106025502.133470-1-liubaolin12138@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Baolin, On 2026/1/6 10:55, Baolin Liu wrote: > From: Baolin Liu > > When updating fsid or domain_id, the code frees the old pointer before > allocating a new one. If allocation fails, the pointer becomes NULL > while the old value is already freed, causing state inconsistency. > > Fix by allocating the new value first, and only freeing the old value > on success. > > Signed-off-by: Baolin Liu > --- > fs/erofs/super.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/fs/erofs/super.c b/fs/erofs/super.c > index 937a215f626c..6e083d7e634c 100644 > --- a/fs/erofs/super.c > +++ b/fs/erofs/super.c > @@ -509,16 +509,22 @@ static int erofs_fc_parse_param(struct fs_context *fc, > break; > #ifdef CONFIG_EROFS_FS_ONDEMAND > case Opt_fsid: > - kfree(sbi->fsid); > - sbi->fsid = kstrdup(param->string, GFP_KERNEL); > - if (!sbi->fsid) > + char *new_fsid; could you move char *new_fsid, *new_domain_id; to the beginning of `erofs_fc_parse_param()` to avoid variable definitions in the switch statement? or maybe just call it as: char *newstr; Thanks, Gao Xiang > + > + new_fsid = kstrdup(param->string, GFP_KERNEL); > + if (!new_fsid) > return -ENOMEM; > + kfree(sbi->fsid); > + sbi->fsid = new_fsid; > break; > case Opt_domain_id: > - kfree(sbi->domain_id); > - sbi->domain_id = kstrdup(param->string, GFP_KERNEL); > - if (!sbi->domain_id) > + char *new_domain_id; > + > + new_domain_id = kstrdup(param->string, GFP_KERNEL); > + if (!new_domain_id) > return -ENOMEM; > + kfree(sbi->domain_id); > + sbi->domain_id = new_domain_id; > break; > #else > case Opt_fsid: