Skip to contentSkip to conversation

kernel/bpf/sys_call.c:76:9: error: '__NR_newfstatat' undeclared here (not in a function)

PATCH kernel test robot 1 participant 1 message Nov 29

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://github.com/kkdwivedi/linux fermata
head:   a93b167d1893f89b1b1e647dac9b51925f94c2e5
commit: 330e827fdc977bf8b90c4bba9780325bacc27474 [72/444] bpf: Let a syscall program make system calls for its process's threads
config: um-randconfig-r2105-20261129 (https://download.01.org/0day-ci/archive/20261129/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261129/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> kernel/bpf/sys_call.c:76:9: error: '__NR_newfstatat' undeclared here (not in a function)
      76 |         __NR_newfstatat, __NR_statx, __NR_statfs, __NR_fstatfs, __NR_access, __NR_faccessat,
         |         ^~~~~~~~~~~~~~~
>> kernel/bpf/sys_call.c:82:63: error: '__NR_accept' undeclared here (not in a function); did you mean '__sys_accept4'?
      82 |         __NR_socket, __NR_socketpair, __NR_bind, __NR_listen, __NR_accept, __NR_accept4,
         |                                                               ^~~~~~~~~~~
         |                                                               __sys_accept4
   kernel/bpf/sys_call.c: In function 'bpf_sys_call':
   kernel/bpf/sys_call.c:218:13: error: 'struct pt_regs' has no member named 'orig_ax'
     218 |         regs.orig_ax = nr;
         |             ^
   kernel/bpf/sys_call.c:219:13: error: 'struct pt_regs' has no member named 'di'
     219 |         regs.di = args[0];
         |             ^
   kernel/bpf/sys_call.c:220:13: error: 'struct pt_regs' has no member named 'si'
     220 |         regs.si = args[1];
         |             ^
   kernel/bpf/sys_call.c:221:13: error: 'struct pt_regs' has no member named 'dx'
     221 |         regs.dx = args[2];
         |             ^
   kernel/bpf/sys_call.c:222:13: error: 'struct pt_regs' has no member named 'r10'
     222 |         regs.r10 = args[3];
         |             ^
   kernel/bpf/sys_call.c:223:13: error: 'struct pt_regs' has no member named 'r8'
     223 |         regs.r8 = args[4];
         |             ^
   kernel/bpf/sys_call.c:224:13: error: 'struct pt_regs' has no member named 'r9'
     224 |         regs.r9 = args[5];
         |             ^
>> kernel/bpf/sys_call.c:243:34: warning: passing argument 1 of 'sys_call_table[nr]' makes integer from pointer without a cast [-Wint-conversion]
     243 |         ret = sys_call_table[nr](&regs);
         |                                  ^~~~~
         |                                  |
         |                                  struct pt_regs *
   kernel/bpf/sys_call.c:243:34: note: expected 'long unsigned int' but argument is of type 'struct pt_regs *'
   kernel/bpf/sys_call.c:243:15: error: too few arguments to function 'sys_call_table[nr]'
     243 |         ret = sys_call_table[nr](&regs);
         |               ^~~~~~~~~~~~~~

vim +/__NR_newfstatat +76 kernel/bpf/sys_call.c

    66	
    67	/* Calls for any thread of the process. */
    68	static const u16 bpf_sys_call_process[] __initconst = {
    69		__NR_read, __NR_write, __NR_pread64, __NR_pwrite64, __NR_readv, __NR_writev,
    70		__NR_preadv, __NR_pwritev, __NR_preadv2, __NR_pwritev2,
    71		__NR_sendfile, __NR_splice, __NR_tee, __NR_copy_file_range,
    72		__NR_lseek, __NR_close, __NR_dup, __NR_dup2, __NR_dup3, __NR_fcntl, __NR_flock,
    73		__NR_fsync, __NR_fdatasync, __NR_sync_file_range, __NR_truncate, __NR_ftruncate,
    74		__NR_fallocate, __NR_fadvise64,
    75		__NR_open, __NR_openat, __NR_openat2, __NR_creat, __NR_stat, __NR_fstat, __NR_lstat,
  > 76		__NR_newfstatat, __NR_statx, __NR_statfs, __NR_fstatfs, __NR_access, __NR_faccessat,
    77		__NR_faccessat2, __NR_getdents64, __NR_getcwd, __NR_mkdir, __NR_mkdirat, __NR_rmdir,
    78		__NR_unlink, __NR_unlinkat, __NR_rename, __NR_renameat, __NR_renameat2, __NR_link,
    79		__NR_linkat, __NR_symlink, __NR_symlinkat, __NR_readlink, __NR_readlinkat,
    80		__NR_chmod, __NR_fchmod, __NR_fchmodat, __NR_chown, __NR_fchown, __NR_lchown,
    81		__NR_fchownat, __NR_utimensat, __NR_memfd_create,
  > 82		__NR_socket, __NR_socketpair, __NR_bind, __NR_listen, __NR_accept, __NR_accept4,
    83		__NR_connect, __NR_shutdown, __NR_sendto, __NR_recvfrom, __NR_sendmsg, __NR_recvmsg,
    84		__NR_sendmmsg, __NR_recvmmsg, __NR_setsockopt, __NR_getsockopt, __NR_getsockname,
    85		__NR_getpeername,
    86		__NR_pipe, __NR_pipe2, __NR_eventfd, __NR_eventfd2, __NR_epoll_create,
    87		__NR_epoll_create1, __NR_epoll_ctl, __NR_epoll_wait, __NR_poll, __NR_select,
    88		__NR_mmap, __NR_munmap, __NR_mprotect, __NR_madvise, __NR_mremap, __NR_msync,
    89		__NR_mincore, __NR_mlock, __NR_munlock, __NR_brk,
    90		__NR_getpid, __NR_getppid, __NR_getuid, __NR_geteuid, __NR_getgid, __NR_getegid,
    91		__NR_getrandom, __NR_uname, __NR_sysinfo, __NR_clock_gettime, __NR_clock_getres,
    92		__NR_gettimeofday, __NR_time,
    93	};
    94	
    95	/*
    96	 * Calls for the calling thread only: made for another one, they would wait,
    97	 * sleep, move or answer for the wrong thread, or record its id as an owner.
    98	 */
    99	static const u16 bpf_sys_call_self[] __initconst = {
   100		__NR_futex, __NR_gettid, __NR_getcpu, __NR_getrusage, __NR_sched_yield,
   101		__NR_sched_setaffinity, __NR_sched_getaffinity, __NR_nanosleep, __NR_clock_nanosleep,
   102	};
   103	
   104	static DECLARE_BITMAP(bpf_sys_call_for_process, NR_syscalls) __ro_after_init;
   105	static DECLARE_BITMAP(bpf_sys_call_for_self, NR_syscalls) __ro_after_init;
   106	
   107	/*
   108	 * Whether @task has what a call made by the current thread would use in its
   109	 * place: the file table, the fs and the namespaces, and no filter or audit
   110	 * that the call would pass by. The pointers are compared, not followed: each
   111	 * changes only by its own thread, and a call that raced with such a change
   112	 * was made before it.
   113	 */
   114	/* struct seccomp has no mode without CONFIG_SECCOMP, and no task a filter */
   115	static bool bpf_sys_call_seccomp(struct task_struct *task)
   116	{
   117	#ifdef CONFIG_SECCOMP
   118		return READ_ONCE(task->seccomp.mode);
   119	#else
   120		return false;
   121	#endif
   122	}
   123	
   124	static int bpf_sys_call_check(struct task_struct *task)
   125	{
   126		if (task != current) {
   127			if (!same_thread_group(task, current))
   128				return -EPERM;
   129			if (READ_ONCE(task->flags) & PF_EXITING)
   130				return -ESRCH;
   131			if (READ_ONCE(task->files) != current->files ||
   132			    READ_ONCE(task->fs) != current->fs ||
   133			    READ_ONCE(task->nsproxy) != current->nsproxy)
   134				return -EPERM;
   135		}
   136		if (bpf_sys_call_seccomp(current) || bpf_sys_call_seccomp(task))
   137			return -EPERM;
   138		if (!audit_dummy_context())
   139			return -EPERM;
   140		return 0;
   141	}
   142	
   143	/*
   144	 * The work that the return to user mode would run for the calling thread:
   145	 * the release of a file whose last reference a call dropped, above all,
   146	 * which would otherwise wait until the thread leaves the program. io threads run theirs
   147	 * the same way, see io_run_task_work().
   148	 */
   149	static void bpf_sys_call_task_work(void)
   150	{
   151		if (test_thread_flag(TIF_NOTIFY_SIGNAL))
   152			clear_notify_signal();
   153		if (task_work_pending(current)) {
   154			__set_current_state(TASK_RUNNING);
   155			task_work_run();
   156		}
   157	}
   158	
   159	__bpf_kfunc_start_defs();
   160	
   161	/**
   162	 * bpf_sys_call - Make a system call for a thread of the caller's process
   163	 * @task: the thread the call is made for, the calling thread or another one
   164	 *	  of its process
   165	 * @nr: the system call's number
   166	 * @args: its six arguments
   167	 * @args__sz: the size of @args, 48
   168	 * @aux: the calling program, set by the verifier
   169	 *
   170	 * Makes system call @nr in the calling thread, a thread of a user process
   171	 * running a syscall program, as @task would make it: see the comment at the
   172	 * top for what is the task's and what is refused. Pointers in @args are user
   173	 * addresses of the process.
   174	 *
   175	 * For the verifier the call is a park, see bpf_task_park(): the program
   176	 * leaves its Tasks Trace RCU read section and may migrate for the time of the
   177	 * call, which may sleep for as long as the system call does, and the time
   178	 * slice of its loops starts over when it returns.
   179	 *
   180	 * Signals are delivered on the return to user mode, which the call does not
   181	 * make. A call that a signal interrupted returns -ERESTARTSYS,
   182	 * -ERESTARTNOINTR, -ERESTARTNOHAND or -ERESTART_RESTARTBLOCK, as the system
   183	 * call gave it: it did nothing, and the program makes it again once the
   184	 * thread has been to user mode, or completes it with -EINTR. The program does
   185	 * not hand those codes to user space. A call is not begun while a signal is
   186	 * pending: that returns -ERESTARTNOINTR. Work queued for the thread's return
   187	 * to user mode, the release of a file whose last reference a call dropped
   188	 * among it, is run before and after the call.
   189	 *
   190	 * Return: what the system call returned, or -EINVAL if @args__sz is not 48,
   191	 * -ENOSYS if @nr is not a call that may be made for @task, -EPERM if the
   192	 * calling thread is not a thread of a user process, @task is not of its
   193	 * process or does not have its files, fs or namespaces, or a seccomp filter
   194	 * or syscall auditing applies, -ESRCH if @task is exiting, and
   195	 * -ERESTARTNOINTR if a signal is pending.
   196	 */
   197	__bpf_kfunc long bpf_sys_call(struct task_struct *task, u32 nr, const u64 *args, u32 args__sz,
   198				      struct bpf_prog_aux *aux)
   199	{
   200		const struct cred *cred = NULL, *old;
   201		struct pt_regs regs = {};
   202		long ret;
   203	
   204		if (args__sz != 6 * sizeof(u64))
   205			return -EINVAL;
   206		if (!current->mm || (current->flags & (PF_KTHREAD | PF_USER_WORKER)))
   207			return -EPERM;
   208		if (nr >= NR_syscalls)
   209			return -ENOSYS;
   210		nr = array_index_nospec(nr, NR_syscalls);
   211		if (!test_bit(nr, bpf_sys_call_for_process) &&
   212		    !(task == current && test_bit(nr, bpf_sys_call_for_self)))
   213			return -ENOSYS;
   214		ret = bpf_sys_call_check(task);
   215		if (ret)
   216			return ret;
   217	
   218		regs.orig_ax = nr;
   219		regs.di = args[0];
   220		regs.si = args[1];
   221		regs.dx = args[2];
   222		regs.r10 = args[3];
   223		regs.r8 = args[4];
   224		regs.r9 = args[5];
   225	
   226		/* What bpf_task_park() does for its sleep, and for the same reasons. */
   227		migrate_enable();
   228		rcu_read_unlock_trace();
   229	
   230		bpf_sys_call_task_work();
   231		if (signal_pending(current)) {
   232			ret = -ERESTARTNOINTR;
   233			goto out;
   234		}
   235		/*
   236		 * The task's objective credentials: its subjective ones may be an
   237		 * override that a call of its own made for itself for a while.
   238		 */
   239		if (task != current && rcu_access_pointer(task->real_cred) != current_cred())
   240			cred = get_task_cred(task);
   241		if (cred)
   242			old = override_creds(cred);
 > 243		ret = sys_call_table[nr](&regs);

244 if (cred) {
245 revert_creds(old);
246 put_cred(cred);
247 }
248 bpf_sys_call_task_work();
249 out:
250 rcu_read_lock_trace();
251 migrate_disable();
252 bpf_timed_may_goto_rearm(aux);
253 return ret;
254 }
255

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki