@@ -108,10 +108,10 @@ struct kbox_dispatch forward_readlinkat(const struct kbox_syscall_request *req,
108108 struct kbox_supervisor_ctx * ctx )
109109{
110110 pid_t pid = kbox_syscall_request_pid (req );
111- long dirfd_raw = to_dirfd_arg ( kbox_syscall_request_arg ( req , 0 )) ;
112- char pathbuf [ KBOX_MAX_PATH ] ;
113- int rc = guest_mem_read_string ( ctx , pid , kbox_syscall_request_arg ( req , 1 ) ,
114- pathbuf , sizeof (pathbuf ) );
111+ char translated [ KBOX_MAX_PATH ] ;
112+ long lkl_dirfd ;
113+ int rc = translate_request_at_path ( req , ctx , 0 , 1 , translated ,
114+ sizeof (translated ), & lkl_dirfd );
115115 if (rc < 0 )
116116 return kbox_dispatch_errno (- rc );
117117
@@ -123,15 +123,7 @@ struct kbox_dispatch forward_readlinkat(const struct kbox_syscall_request *req,
123123
124124 if (remote_buf == 0 )
125125 return kbox_dispatch_errno (EFAULT );
126-
127- char translated [KBOX_MAX_PATH ];
128- rc = kbox_translate_path_for_lkl (pid , pathbuf , ctx -> host_root , translated ,
129- sizeof (translated ));
130- if (rc < 0 )
131- return kbox_dispatch_errno (- rc );
132-
133- long lkl_dirfd = resolve_open_dirfd (translated , dirfd_raw , ctx -> fd_table );
134- if (lkl_dirfd < 0 && lkl_dirfd != AT_FDCWD_LINUX )
126+ if (should_continue_for_dirfd (lkl_dirfd ))
135127 return kbox_dispatch_continue ();
136128
137129 if (bufsiz > KBOX_MAX_PATH )
@@ -724,29 +716,20 @@ struct kbox_dispatch forward_symlinkat(const struct kbox_syscall_request *req,
724716{
725717 pid_t pid = kbox_syscall_request_pid (req );
726718 char targetbuf [KBOX_MAX_PATH ];
727- char linkpathbuf [KBOX_MAX_PATH ];
728719 int rc ;
729720
730721 rc = guest_mem_read_string (ctx , pid , kbox_syscall_request_arg (req , 0 ),
731722 targetbuf , sizeof (targetbuf ));
732723 if (rc < 0 )
733724 return kbox_dispatch_errno (- rc );
734725
735- long newdirfd_raw = to_dirfd_arg (kbox_syscall_request_arg (req , 1 ));
736-
737- rc = guest_mem_read_string (ctx , pid , kbox_syscall_request_arg (req , 2 ),
738- linkpathbuf , sizeof (linkpathbuf ));
739- if (rc < 0 )
740- return kbox_dispatch_errno (- rc );
741-
742726 char linktrans [KBOX_MAX_PATH ];
743- rc = kbox_translate_path_for_lkl (pid , linkpathbuf , ctx -> host_root ,
744- linktrans , sizeof (linktrans ));
727+ long newdirfd ;
728+ rc = translate_request_at_path (req , ctx , 1 , 2 , linktrans , sizeof (linktrans ),
729+ & newdirfd );
745730 if (rc < 0 )
746731 return kbox_dispatch_errno (- rc );
747-
748- long newdirfd = resolve_open_dirfd (linktrans , newdirfd_raw , ctx -> fd_table );
749- if (newdirfd < 0 && newdirfd != AT_FDCWD_LINUX )
732+ if (should_continue_for_dirfd (newdirfd ))
750733 return kbox_dispatch_continue ();
751734
752735 /* Target is stored as-is (not translated). */
@@ -759,44 +742,25 @@ struct kbox_dispatch forward_symlinkat(const struct kbox_syscall_request *req,
759742struct kbox_dispatch forward_linkat (const struct kbox_syscall_request * req ,
760743 struct kbox_supervisor_ctx * ctx )
761744{
762- pid_t pid = kbox_syscall_request_pid (req );
763- long olddirfd_raw = to_dirfd_arg (kbox_syscall_request_arg (req , 0 ));
764- char oldpathbuf [KBOX_MAX_PATH ];
765745 int rc ;
766-
767- rc = guest_mem_read_string (ctx , pid , kbox_syscall_request_arg (req , 1 ),
768- oldpathbuf , sizeof (oldpathbuf ));
769- if (rc < 0 )
770- return kbox_dispatch_errno (- rc );
771-
772- long newdirfd_raw = to_dirfd_arg (kbox_syscall_request_arg (req , 2 ));
773- char newpathbuf [KBOX_MAX_PATH ];
774-
775- rc = guest_mem_read_string (ctx , pid , kbox_syscall_request_arg (req , 3 ),
776- newpathbuf , sizeof (newpathbuf ));
777- if (rc < 0 )
778- return kbox_dispatch_errno (- rc );
779-
780746 long flags = to_c_long_arg (kbox_syscall_request_arg (req , 4 ));
781747
782748 char oldtrans [KBOX_MAX_PATH ];
783- rc = kbox_translate_path_for_lkl (pid , oldpathbuf , ctx -> host_root , oldtrans ,
784- sizeof (oldtrans ));
749+ long olddirfd ;
750+ rc = translate_request_at_path (req , ctx , 0 , 1 , oldtrans , sizeof (oldtrans ),
751+ & olddirfd );
785752 if (rc < 0 )
786753 return kbox_dispatch_errno (- rc );
754+ if (should_continue_for_dirfd (olddirfd ))
755+ return kbox_dispatch_continue ();
787756
788757 char newtrans [KBOX_MAX_PATH ];
789- rc = kbox_translate_path_for_lkl (pid , newpathbuf , ctx -> host_root , newtrans ,
790- sizeof (newtrans ));
758+ long newdirfd ;
759+ rc = translate_request_at_path (req , ctx , 2 , 3 , newtrans , sizeof (newtrans ),
760+ & newdirfd );
791761 if (rc < 0 )
792762 return kbox_dispatch_errno (- rc );
793-
794- long olddirfd = resolve_open_dirfd (oldtrans , olddirfd_raw , ctx -> fd_table );
795- if (olddirfd < 0 && olddirfd != AT_FDCWD_LINUX )
796- return kbox_dispatch_continue ();
797-
798- long newdirfd = resolve_open_dirfd (newtrans , newdirfd_raw , ctx -> fd_table );
799- if (newdirfd < 0 && newdirfd != AT_FDCWD_LINUX )
763+ if (should_continue_for_dirfd (newdirfd ))
800764 return kbox_dispatch_continue ();
801765
802766 long ret = kbox_lkl_linkat (ctx -> sysnrs , olddirfd , oldtrans , newdirfd ,
@@ -824,20 +788,12 @@ struct kbox_dispatch forward_utimensat(const struct kbox_syscall_request *req,
824788 int rc ;
825789
826790 if (kbox_syscall_request_arg (req , 1 ) != 0 ) {
827- char pathbuf [KBOX_MAX_PATH ];
828- rc = guest_mem_read_string (ctx , pid , kbox_syscall_request_arg (req , 1 ),
829- pathbuf , sizeof (pathbuf ));
791+ rc = translate_request_at_path (req , ctx , 0 , 1 , translated ,
792+ sizeof (translated ), & lkl_dirfd );
830793 if (rc < 0 )
831794 return kbox_dispatch_errno (- rc );
832-
833- rc = kbox_translate_path_for_lkl (pid , pathbuf , ctx -> host_root ,
834- translated , sizeof (translated ));
835- if (rc < 0 )
836- return kbox_dispatch_errno (- rc );
837-
838795 translated_path = translated ;
839- lkl_dirfd = resolve_open_dirfd (translated , dirfd_raw , ctx -> fd_table );
840- if (lkl_dirfd < 0 && lkl_dirfd != AT_FDCWD_LINUX )
796+ if (should_continue_for_dirfd (lkl_dirfd ))
841797 return kbox_dispatch_continue ();
842798 } else {
843799 translated_path = NULL ;
0 commit comments