mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthias Goergens <matthias.goergens@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/4] isofs: pass the name buffer size to get_rock_ridge_filename()
Date: Sat, 26 Sep 2026 12:29:15 +0800	[thread overview]
Message-ID: <20260926042916.3277409-4-matthias.goergens@gmail.com> (raw)
In-Reply-To: <20260926042916.3277409-1-matthias.goergens@gmail.com>

get_rock_ridge_filename() assembles a name from one or more NM entries
into a buffer allocated by its caller.  It is not told how big that
buffer is, and instead stops adding NM entries once the name would
exceed NAME_MAX, relying on the callers' buffer being larger.

Pass the size in and check against it.  Both callers pass NAME_MAX + 1,
so the behaviour is unchanged: an NM entry that would take the name
past 255 bytes is dropped, together with any that follow, and the
entries before it are returned.

Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
---
 fs/isofs/dir.c   | 3 ++-
 fs/isofs/isofs.h | 3 ++-
 fs/isofs/namei.c | 3 ++-
 fs/isofs/rock.c  | 8 ++++++--
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
index eebea133094d..dd8958617340 100644
--- a/fs/isofs/dir.c
+++ b/fs/isofs/dir.c
@@ -186,7 +186,8 @@ static int do_isofs_readdir(struct inode *inode, struct file *file,
 
 		map = 1;
 		if (sbi->s_rock) {
-			len = get_rock_ridge_filename(de, tmpname, inode);
+			len = get_rock_ridge_filename(de, tmpname, NAME_MAX + 1,
+						      inode);
 			if (len != 0) {		/* may be -1 */
 				p = tmpname;
 				map = 0;
diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
index 47c43a3c6a61..a2d28a23e892 100644
--- a/fs/isofs/isofs.h
+++ b/fs/isofs/isofs.h
@@ -115,7 +115,8 @@ struct timespec64 iso_date(u8 *p, int flags);
 struct inode;		/* To make gcc happy */
 
 extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
-extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
+int get_rock_ridge_filename(struct iso_directory_record *de, char *retname,
+			    int retnamesize, struct inode *inode);
 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
 bool isofs_dir_record_valid(struct iso_directory_record *de,
 			    unsigned long offset,
diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c
index c65cc78583ba..9025ff74eb60 100644
--- a/fs/isofs/namei.c
+++ b/fs/isofs/namei.c
@@ -104,7 +104,8 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry,
 		dpnt = de->name;
 
 		if (sbi->s_rock &&
-		    ((i = get_rock_ridge_filename(de, tmpname, dir)))) {
+		    ((i = get_rock_ridge_filename(de, tmpname, NAME_MAX + 1,
+						  dir)))) {
 			dlen = i;	/* possibly -1 */
 			dpnt = tmpname;
 #ifdef CONFIG_JOLIET
diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
index 84e0d764c210..5a5984b72224 100644
--- a/fs/isofs/rock.c
+++ b/fs/isofs/rock.c
@@ -209,10 +209,14 @@ static int rock_check_overflow(struct rock_state *rs, int sig)
 }
 
 /*
+ * Build the Rock Ridge name of @de in @retname, a buffer of @retnamesize
+ * bytes.  From the first NM entry that does not fit along with the
+ * terminator, the rest of the name is dropped.
+ *
  * return length of name field; 0: not found, -1: to be ignored
  */
 int get_rock_ridge_filename(struct iso_directory_record *de,
-			    char *retname, struct inode *inode)
+			    char *retname, int retnamesize, struct inode *inode)
 {
 	struct rock_state rs;
 	struct rock_ridge *rr;
@@ -287,7 +291,7 @@ int get_rock_ridge_filename(struct iso_directory_record *de,
 				break;
 			}
 			len = rr->len - 5;
-			if (retnamlen + len > NAME_MAX) {
+			if (retnamlen + len >= retnamesize) {
 				truncate = 1;
 				break;
 			}
-- 
2.55.0


  parent reply	other threads:[~2026-09-26  4:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26  4:29 [PATCH v2 0/4] isofs: bound the name conversion and return long Joliet names whole Matthias Goergens
2026-09-26  4:29 ` [PATCH v2 1/4] isofs: " Matthias Goergens
2026-09-26  4:29 ` [PATCH v2 2/4] isofs: report the Joliet name length in statfs Matthias Goergens
2026-09-26  4:29 ` Matthias Goergens [this message]
2026-09-26  4:29 ` [PATCH v2 4/4] isofs: shrink the name conversion buffer Matthias Goergens
2026-09-30 11:13 ` [PATCH v2 0/4] isofs: bound the name conversion and return long Joliet names whole Jan Kara

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=20260926042916.3277409-4-matthias.goergens@gmail.com \
    --to=matthias.goergens@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®