[PATCH] bcachefs: Lower BCH_NAME_MAX to 512

Subsystems: filesystems (vfs and infrastructure), the rest

STALE1162d

4 messages, 2 authors, 2023-08-13 · open the first message on its own page

[PATCH] bcachefs: Lower BCH_NAME_MAX to 512

From: Joshua Ashton <hidden>
Date: 2023-08-12 23:59:52

To ensure we aren't shooting ourselves in the foot after merge for
potentially doing future revisions for dirent or for storing multiple
names for casefolding, limit this to 512 for now.

Previously this define was linked to the max size a d_name in
bch_dirent could be.

Signed-off-by: Joshua Ashton <redacted>
---
 fs/bcachefs/bcachefs_format.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 5ec218ee3569..23bae622309c 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -916,9 +916,7 @@ struct bch_dirent {
 #define DT_SUBVOL	16
 #define BCH_DT_MAX	17
 
-#define BCH_NAME_MAX	((unsigned) (U8_MAX * sizeof(__u64) -		\
-			 sizeof(struct bkey) -				\
-			 offsetof(struct bch_dirent, d_name)))
+#define BCH_NAME_MAX	512
 
 /* Xattrs */
 
-- 
2.41.0

Re: [PATCH] bcachefs: Lower BCH_NAME_MAX to 512

From: Kent Overstreet <kent.overstreet@linux.dev>
Date: 2023-08-13 15:10:44

On Sun, Aug 13, 2023 at 12:59:17AM +0100, Joshua Ashton wrote:
To ensure we aren't shooting ourselves in the foot after merge for
potentially doing future revisions for dirent or for storing multiple
names for casefolding, limit this to 512 for now.
Any time you're changing something - always grep to see how it's used:

bch2_dirent_invalid():

        if (d_name.len > BCH_NAME_MAX) {                                                                                                                                                                                                                                                 
                prt_printf(err, "dirent name too big (%u > %u)",                                                                                                                                                                                                                         
                       d_name.len, BCH_NAME_MAX);                                                                                                                                                                                                                                        
                return -BCH_ERR_invalid_bkey;                                                                                                                                                                                                                                            
        }

We'll need to either delete that check, or only run it for new keys
(flags & BKEY_INVALID_COMMIT), we don't want to be deleting existing
dirents
quoted hunk
Previously this define was linked to the max size a d_name in
bch_dirent could be.

Signed-off-by: Joshua Ashton <redacted>
---
 fs/bcachefs/bcachefs_format.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 5ec218ee3569..23bae622309c 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -916,9 +916,7 @@ struct bch_dirent {
 #define DT_SUBVOL	16
 #define BCH_DT_MAX	17
 
-#define BCH_NAME_MAX	((unsigned) (U8_MAX * sizeof(__u64) -		\
-			 sizeof(struct bkey) -				\
-			 offsetof(struct bch_dirent, d_name)))
+#define BCH_NAME_MAX	512
 
 /* Xattrs */
 
-- 
2.41.0

Re: [PATCH] bcachefs: Lower BCH_NAME_MAX to 512

From: Joshua Ashton <hidden>
Date: 2023-08-13 15:29:56


On 8/13/23 16:10, Kent Overstreet wrote:
On Sun, Aug 13, 2023 at 12:59:17AM +0100, Joshua Ashton wrote:
quoted
To ensure we aren't shooting ourselves in the foot after merge for
potentially doing future revisions for dirent or for storing multiple
names for casefolding, limit this to 512 for now.
Any time you're changing something - always grep to see how it's used:
Was aware it was used here, but wasn't sure what you were willing to accept in terms of compat.
bch2_dirent_invalid():

         if (d_name.len > BCH_NAME_MAX) {
                 prt_printf(err, "dirent name too big (%u > %u)",
                        d_name.len, BCH_NAME_MAX);
                 return -BCH_ERR_invalid_bkey;
         }

We'll need to either delete that check, or only run it for new keys
(flags & BKEY_INVALID_COMMIT), we don't want to be deleting existing
dirents
It isn't actually possible for this check to even trigger with the old BCH_NAME_MAX given how the length was calculated and the value of it.

Makes sense to just change it to a check on COMMIT for new keys with the new size..
(Should also never happen, but makes sense for sanity.)

- Joshie 🐸✨
quoted
Previously this define was linked to the max size a d_name in
bch_dirent could be.

Signed-off-by: Joshua Ashton <redacted>
---
  fs/bcachefs/bcachefs_format.h | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 5ec218ee3569..23bae622309c 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -916,9 +916,7 @@ struct bch_dirent {
  #define DT_SUBVOL	16
  #define BCH_DT_MAX	17
  
-#define BCH_NAME_MAX	((unsigned) (U8_MAX * sizeof(__u64) -		\
-			 sizeof(struct bkey) -				\
-			 offsetof(struct bch_dirent, d_name)))
+#define BCH_NAME_MAX	512
  
  /* Xattrs */
  
-- 
2.41.0

Re: [PATCH] bcachefs: Lower BCH_NAME_MAX to 512

From: Kent Overstreet <kent.overstreet@linux.dev>
Date: 2023-08-13 15:43:12

On Sun, Aug 13, 2023 at 04:29:52PM +0100, Joshua Ashton wrote:

On 8/13/23 16:10, Kent Overstreet wrote:
quoted
On Sun, Aug 13, 2023 at 12:59:17AM +0100, Joshua Ashton wrote:
quoted
To ensure we aren't shooting ourselves in the foot after merge for
potentially doing future revisions for dirent or for storing multiple
names for casefolding, limit this to 512 for now.
Any time you're changing something - always grep to see how it's used:
Was aware it was used here, but wasn't sure what you were willing to accept
in terms of compat.
Make sure to mention things you aren't sure about in the commit message
then, don't leave surprises :)
quoted
bch2_dirent_invalid():

         if (d_name.len > BCH_NAME_MAX) {
                 prt_printf(err, "dirent name too big (%u > %u)",
                        d_name.len, BCH_NAME_MAX);
                 return -BCH_ERR_invalid_bkey;
         }

We'll need to either delete that check, or only run it for new keys
(flags & BKEY_INVALID_COMMIT), we don't want to be deleting existing
dirents
It isn't actually possible for this check to even trigger with the old
BCH_NAME_MAX given how the length was calculated and the value of it.
Yes, but after your patch this check will trigger on any dirents longer
than the new BCH_NAME_MAX, and they'll be deleted.
Makes sense to just change it to a check on COMMIT for new keys with the new
size..
(Should also never happen, but makes sense for sanity.)
Yeah, that's what the .invalid() methods are for - catching bugs before
we write garbage out to disk.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help