mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "zilin@seu.edu.cn" <zilin@seu.edu.cn>
Cc: "jianhao.xu@seu.edu.cn" <jianhao.xu@seu.edu.cn>,
	"sougata@tuxera.com" <sougata@tuxera.com>,
	"frank.li@vivo.com" <frank.li@vivo.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"slava@dubeyko.com" <slava@dubeyko.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE:  [PATCH] hfsplus: fix held lock freed on hfsplus_fill_super()
Date: Mon, 16 Mar 2026 22:46:14 +0000	[thread overview]
Message-ID: <054d2ebe267ef9c13468a05557cb099c49a0b872.camel@ibm.com> (raw)
In-Reply-To: <20260314033603.14211-1-zilin@seu.edu.cn>

On Sat, 2026-03-14 at 11:36 +0800, Zilin Guan wrote:
> On Fri, Mar 13, 2026 at 06:38:14PM +0000, Viacheslav Dubeyko wrote:
> > On Fri, 2026-03-13 at 09:49 +0800, Zilin Guan wrote:
> > > Hi Slava,
> > > 
> > > Thanks for the detailed proposal. However, this proposed refactoring 
> > > changes the existing semantics and introduces a regression.
> > > 
> > 
> > I don't quite follow to your point. I don't suggest to change the logic. I am
> > suggesting the small refactoring without changing the execution flow. Do you
> > mean that current hfsplus_fill_super() logic is incorrect and has bugs?
> 
> Actually, I don't mean the original logic is incorrect. My concern is that 
> extracting this block into a helper makes it very difficult to preserve 
> that correct execution flow without complicating the error handling.
> 
> > > The hidden directory is optional. If hfs_brec_read() fails, the original 
> > > code simply calls hfs_find_exit() and proceeds with the mount. It is a 
> > > non-fatal error.
> > > 
> > 
> > You simply need slightly modify my suggestion to make it right:
> > 
> > err = hfsplus_get_hidden_dir_entry(sb, &entry);
> > if (!err) {
> > 
> > 		if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
> > 			err = -EIO;
> > 			goto finish_logic;
> > 		}
> > 		inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
> > 		if (IS_ERR(inode)) {
> > 			err = PTR_ERR(inode);
> > 			goto finish_logic;
> > 		}
> > 		sbi->hidden_dir = inode;
> > }
> > 
> > I simply shared the raw suggestion but you can make it right.
> 
> The issue with this updated snippet is that it silently ignores fatal 
> errors from hfs_find_init() and hfsplus_cat_build_key() (e.g., -ENOMEM). 
> If they fail, the mount incorrectly continues. In the original code, 
> these correctly trigger goto out_put_root.
> 
> > > In contrast, failures from hfs_find_init() and hfsplus_cat_build_key() are 
> > > fatal and must abort the mount.
> > > 
> > > By wrapping these into a single helper and returning err, the caller can no 
> > > longer distinguish between them. A missing hidden directory will trigger 
> > > if (err) goto process_error; in hfsplus_fill_super(), making it a fatal 
> > > error. This will break mounting for any valid HFS+ volume that lacks the 
> > > private data directory.
> > > 
> > > 
> > 
> > Simply make my suggestion better and correct. That's all.
> > 
> > Thanks,
> > Slava.
> 
> To make the helper completely correct, we face another issue: the original 
> code ignores all errors from hfs_brec_read() (which can return -ENOENT, 
> -EINVAL, -EIO, etc.), treating them as non-fatal.
> 
> If we combine the fatal setup functions and the non-fatal read function 
> into one helper, it cannot simply return a standard error code. It would 
> need to return three distinct states:
> 
> 1. Fatal error -> caller must abort mount.
> 2. Non-fatal read error -> caller must continue mount, but skip init.
> 3. Success -> caller must init hidden_dir.
> 
> To handle all these cases properly, the helper would have to look 
> something like this:
> 
> 	/* Returns < 0 on fatal error, 0 on missing/read error, 1 on success */
> 	static inline int hfsplus_get_hidden_dir_entry(struct super_block *sb,
> 						       hfsplus_cat_entry *entry) 
> 	{
> 		struct hfs_find_data fd;
> 		int err;
> 		int ret = 0;
> 		/* ... init str ... */
> 
> 		err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
> 		if (err)
> 			return err; /* Fatal, fd not initialized */
> 		
> 		err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
> 		if (unlikely(err < 0)) {
> 			ret = err;
> 			goto free_fd; /* Fatal */
> 		}
> 
> 		err = hfs_brec_read(&fd, entry, sizeof(*entry));
> 		if (err) {
> 			ret = 0; /* Non-fatal, but no entry to init */
> 			goto free_fd;
> 		}
> 		
> 		ret = 1; /* Success */
> 
> 	free_fd:
> 		hfs_find_exit(&fd);
> 		return ret;
> 	}
> 
> And the caller:
> 	
> 	err = hfsplus_get_hidden_dir_entry(sb, &entry);
> 	if (err < 0)
> 		goto out_put_root;
> 	if (err == 1) {
> 		/* ... init hidden_dir ... */
> 	}
> 
> We would have to invent a custom return state convention (1, 0, < 0) just to 
> hide a single hfs_find_exit() call.
> 
> Given this, I think the current inline logic in my patch is much cleaner 
> and avoids this convoluted error routing. 
> 
> What do you prefer?
> 

I don't quite follow to your trouble. Any function can return various error
codes and caller could process the different error codes by different logics:

err = hfsplus_get_hidden_dir_entry(sb, &entry);
if (err == -ENOENT) {
  <process -ENOENT>
} else if (err == -EINVAL) {
  <process -EINVAL>
} else if (err == -EIO) {
  <process -EIO>
} else if (err == <some other error>) {
  <process this case>
}

Does it solve your trouble?

Thanks,
Slava.

  reply	other threads:[~2026-03-16 22:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 11:43 Zilin Guan
2026-03-11 21:17 ` Viacheslav Dubeyko
2026-03-12  2:13   ` Zilin Guan
2026-03-12  2:17   ` [PATCH] hfsplus: fix held lock freed on hfsplus_fill_super() Zilin Guan
2026-03-12 17:36     ` Viacheslav Dubeyko
2026-03-13  1:49       ` Zilin Guan
2026-03-13 18:38         ` Viacheslav Dubeyko
2026-03-14  3:36           ` Zilin Guan
2026-03-16 22:46             ` Viacheslav Dubeyko [this message]
2026-03-17  3:12               ` Zilin Guan
2026-03-17 19:36                 ` Viacheslav Dubeyko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=054d2ebe267ef9c13468a05557cb099c49a0b872.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=slava@dubeyko.com \
    --cc=sougata@tuxera.com \
    --cc=stable@vger.kernel.org \
    --cc=zilin@seu.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®