Re: [PATCH v2 1/3] fs: Introduce task path helpers
flat view
From: Chen Linxuan <hidden>
Date: 2026-09-22 05:59:12
Also in:
linux-fsdevel, linux-mm, linux-security-module, lkml
On Tue, Sep 22, 2026 at 3:21 AM Jann Horn [off-list ref] wrote:
On Mon, Aug 31, 2026 at 4:59 AM Chen Linxuan via B4 Relay [off-list ref] wrote:quoted
Introduce helpers that acquire a referenced struct path for a task's executable, root, and working directory. Reuse them for procfs task links and AppArmor executable-path handling instead of duplicating file and path reference handling at each call site.[...]quoted
+/** + * get_task_exe_path - acquire a reference to the task's executable path + * @task: The task. + * @exe_path: The task's executable path. + * + * Returns 0 if the task has an executable path, or -ENOENT if it does not. + * The caller must release the path through path_put() on success. + */ +int get_task_exe_path(struct task_struct *task, struct path *exe_path) +{ + struct file *exe_file = get_task_exe_file(task); + + if (!exe_file) + return -ENOENT; + + *exe_path = exe_file->f_path; + path_get(exe_path); + fput(exe_file); + return 0; +}[...]quoted
static const char *get_current_exe_path(char *buffer, int buffer_size) { - struct file *exe_file; - struct path p; + struct path p __free(path_put) = {}; const char *path_str; - exe_file = get_task_exe_file(current); - if (!exe_file) + if (get_task_exe_path(current, &p)) return ERR_PTR(-ENOENT);This assumes that when get_task_exe_path() fails, it doesn't set members of the path argument to non-NULL values. That should be noted in a comment above get_task_exe_path().
Will be updated in V3.