@@ -145,7 +145,7 @@ open_by_handle_at (int mount_fd, struct file_handle *handle, int flags)
145
145
#define PRIVILEGED_OPAQUE_XATTR "trusted.overlay.opaque"
146
146
#define PRIVILEGED_ORIGIN_XATTR "trusted.overlay.origin"
147
147
#define OPAQUE_WHITEOUT ".wh..wh..opq"
148
- #define WHITEOUT_MAX_LEN (sizeof (OPAQUE_WHITEOUT) )
148
+ #define WHITEOUT_MAX_LEN (sizeof (".wh.")-1 )
149
149
150
150
#if !defined FICLONE && defined __linux__
151
151
# define FICLONE _IOW (0x94, 9, int)
@@ -3583,6 +3583,43 @@ do_getattr (fuse_req_t req, struct fuse_entry_param *e, struct ovl_node *node, i
3583
3583
return 0 ;
3584
3584
}
3585
3585
3586
+ static int
3587
+ do_statfs (struct ovl_data * lo , struct statvfs * sfs )
3588
+ {
3589
+ int ret , fd ;
3590
+
3591
+ fd = get_first_layer (lo )-> fd ;
3592
+
3593
+ if (fd >= 0 )
3594
+ ret = fstatvfs (fd , sfs );
3595
+ else
3596
+ ret = statvfs (lo -> mountpoint , sfs );
3597
+ if (ret < 0 )
3598
+ return ret ;
3599
+
3600
+ sfs -> f_namemax -= WHITEOUT_MAX_LEN ;
3601
+ return 0 ;
3602
+ }
3603
+
3604
+ static short
3605
+ get_fs_namemax (struct ovl_data * lo )
3606
+ {
3607
+ static short namemax = 0 ;
3608
+ if (namemax == 0 )
3609
+ {
3610
+ struct statvfs sfs ;
3611
+ int ret ;
3612
+
3613
+ ret = do_statfs (lo , & sfs );
3614
+ /* On errors use a sane default. */
3615
+ if (ret < 0 )
3616
+ namemax = 255 - WHITEOUT_MAX_LEN ;
3617
+ else
3618
+ namemax = sfs .f_namemax ;
3619
+ }
3620
+ return namemax ;
3621
+ }
3622
+
3586
3623
static void
3587
3624
ovl_create (fuse_req_t req , fuse_ino_t parent , const char * name ,
3588
3625
mode_t mode , struct fuse_file_info * fi )
@@ -3591,12 +3628,19 @@ ovl_create (fuse_req_t req, fuse_ino_t parent, const char *name,
3591
3628
cleanup_close int fd = -1 ;
3592
3629
struct fuse_entry_param e ;
3593
3630
struct ovl_node * node = NULL ;
3631
+ struct ovl_data * lo = ovl_data (req );
3594
3632
struct stat st ;
3595
3633
3596
3634
if (UNLIKELY (ovl_debug (req )))
3597
3635
fprintf (stderr , "ovl_create(parent=%" PRIu64 ", name=%s)\n" ,
3598
3636
parent , name );
3599
3637
3638
+ if (strlen (name ) > get_fs_namemax (lo ))
3639
+ {
3640
+ fuse_reply_err (req , ENAMETOOLONG );
3641
+ return ;
3642
+ }
3643
+
3600
3644
fi -> flags = fi -> flags | O_CREAT ;
3601
3645
3602
3646
fd = ovl_do_open (req , parent , name , fi -> flags , mode , & node , & st );
@@ -3869,6 +3913,12 @@ ovl_link (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, const char *newn
3869
3913
if (UNLIKELY (ovl_debug (req )))
3870
3914
fprintf (stderr , "ovl_link(ino=%" PRIu64 "s, newparent=%" PRIu64 "s, newname=%s)\n" , ino , newparent , newname );
3871
3915
3916
+ if (strlen (newname ) > get_fs_namemax (lo ))
3917
+ {
3918
+ fuse_reply_err (req , ENAMETOOLONG );
3919
+ return ;
3920
+ }
3921
+
3872
3922
node = do_lookup_file (lo , ino , NULL );
3873
3923
if (node == NULL || node -> whiteout )
3874
3924
{
@@ -4008,6 +4058,12 @@ ovl_symlink (fuse_req_t req, const char *link, fuse_ino_t parent, const char *na
4008
4058
if (UNLIKELY (ovl_debug (req )))
4009
4059
fprintf (stderr , "ovl_symlink(link=%s, ino=%" PRIu64 "s, name=%s)\n" , link , parent , name );
4010
4060
4061
+ if (strlen (name ) > get_fs_namemax (lo ))
4062
+ {
4063
+ fuse_reply_err (req , ENAMETOOLONG );
4064
+ return ;
4065
+ }
4066
+
4011
4067
pnode = do_lookup_file (lo , parent , NULL );
4012
4068
if (pnode == NULL || pnode -> whiteout )
4013
4069
{
@@ -4411,9 +4467,17 @@ ovl_rename (fuse_req_t req, fuse_ino_t parent, const char *name,
4411
4467
unsigned int flags )
4412
4468
{
4413
4469
cleanup_lock int l = enter_big_lock ();
4470
+ struct ovl_data * lo = ovl_data (req );
4471
+
4414
4472
if (UNLIKELY (ovl_debug (req )))
4415
4473
fprintf (stderr , "ovl_rename(ino=%" PRIu64 "s, name=%s , ino=%" PRIu64 "s, name=%s)\n" , parent , name , newparent , newname );
4416
4474
4475
+ if (strlen (newname ) > get_fs_namemax (lo ))
4476
+ {
4477
+ fuse_reply_err (req , ENAMETOOLONG );
4478
+ return ;
4479
+ }
4480
+
4417
4481
if (flags & RENAME_EXCHANGE )
4418
4482
ovl_rename_exchange (req , parent , name , newparent , newname , flags );
4419
4483
else
@@ -4423,27 +4487,17 @@ ovl_rename (fuse_req_t req, fuse_ino_t parent, const char *name,
4423
4487
static void
4424
4488
ovl_statfs (fuse_req_t req , fuse_ino_t ino )
4425
4489
{
4426
- int ret , fd ;
4490
+ int ret ;
4427
4491
struct statvfs sfs ;
4428
4492
struct ovl_data * lo = ovl_data (req );
4429
4493
4430
- if (UNLIKELY (ovl_debug (req )))
4431
- fprintf (stderr , "ovl_statfs(ino=%" PRIu64 "s)\n" , ino );
4432
-
4433
- fd = get_first_layer (lo )-> fd ;
4434
-
4435
- if (fd >= 0 )
4436
- ret = fstatvfs (fd , & sfs );
4437
- else
4438
- ret = statvfs (lo -> mountpoint , & sfs );
4494
+ ret = do_statfs (lo , & sfs );
4439
4495
if (ret < 0 )
4440
4496
{
4441
4497
fuse_reply_err (req , errno );
4442
4498
return ;
4443
4499
}
4444
4500
4445
- sfs .f_namemax -= WHITEOUT_MAX_LEN ;
4446
-
4447
4501
fuse_reply_statfs (req , & sfs );
4448
4502
}
4449
4503
@@ -4555,6 +4609,12 @@ ovl_mknod (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev
4555
4609
fprintf (stderr , "ovl_mknod(ino=%" PRIu64 ", name=%s, mode=%d, rdev=%lu)\n" ,
4556
4610
parent , name , mode , rdev );
4557
4611
4612
+ if (strlen (name ) > get_fs_namemax (lo ))
4613
+ {
4614
+ fuse_reply_err (req , ENAMETOOLONG );
4615
+ return ;
4616
+ }
4617
+
4558
4618
mode = mode & ~ctx -> umask ;
4559
4619
4560
4620
node = do_lookup_file (lo , parent , name );
@@ -4665,6 +4725,13 @@ ovl_mkdir (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode)
4665
4725
fprintf (stderr , "ovl_mkdir(ino=%" PRIu64 ", name=%s, mode=%d)\n" ,
4666
4726
parent , name , mode );
4667
4727
4728
+
4729
+ if (strlen (name ) > get_fs_namemax (lo ))
4730
+ {
4731
+ fuse_reply_err (req , ENAMETOOLONG );
4732
+ return ;
4733
+ }
4734
+
4668
4735
node = do_lookup_file (lo , parent , name );
4669
4736
if (node != NULL && !node -> whiteout )
4670
4737
{
0 commit comments