Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ autoreconf -v -f --install "$(dirname "$0")" || exit 1

CFLAGS="-O2"
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Wformat=2"
CFLAGS="$CFLAGS -Wextra"
CFLAGS="$CFLAGS -Werror=discarded-qualifiers"
CFLAGS="$CFLAGS -Werror=format"
Comment thread
haxtibal marked this conversation as resolved.
CFLAGS="$CFLAGS -Werror=implicit-function-declaration"
CFLAGS="$CFLAGS -Werror=implicit-int"
CFLAGS="$CFLAGS -Werror=incompatible-pointer-types"
Expand Down
21 changes: 10 additions & 11 deletions lib/user_busy.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


Comment thread
haxtibal marked this conversation as resolved.
#ifdef __linux__
static int check_status (const char *name, const char *sname, uid_t uid);
static int check_status (const char *name, uid_t uid, pid_t pid, pid_t tid);
static int user_busy_processes (const char *name, uid_t uid);
#else /* !__linux__ */
static int user_busy_utmp (const char *name);
Expand Down Expand Up @@ -94,13 +94,13 @@ user_busy_utmp(const char *name)
#ifdef __linux__
#ifdef ENABLE_SUBIDS
#define in_parentuid_range(uid) ((uid) >= parentuid && (uid) < parentuid + range)
static int different_namespace (const char *sname)
static int different_namespace (pid_t pid, pid_t tid)
{
Comment thread
haxtibal marked this conversation as resolved.
/* 41: /proc/xxxxxxxxxx/task/xxxxxxxxxx/ns/user + \0 */
char path[41];
char buf[512], buf2[512];

stprintf_a(path, "/proc/%s/ns/user", sname);
stprintf_a(path, "/proc/%d/task/%d/ns/user", pid, tid);
Comment thread
alejandro-colomar marked this conversation as resolved.

if (readlinknul_a(path, buf) == -1)
return 0;
Expand All @@ -116,14 +116,14 @@ static int different_namespace (const char *sname)
#endif /* ENABLE_SUBIDS */


static int check_status (const char *name, const char *sname, uid_t uid)
static int check_status (const char *name, uid_t uid, pid_t pid, pid_t tid)
{
/* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */
char status[40];
char line[1024];
FILE *sfile;

stprintf_a(status, "/proc/%s/status", sname);
stprintf_a(status, "/proc/%d/task/%d/status", pid, tid);

sfile = fopen (status, "r");
if (NULL == sfile) {
Expand All @@ -144,7 +144,7 @@ static int check_status (const char *name, const char *sname, uid_t uid)
return 1;
}
#ifdef ENABLE_SUBIDS
if ( different_namespace (sname)
if ( different_namespace (pid, tid)
&& ( have_sub_uids(name, ruid, 1)
|| have_sub_uids(name, euid, 1)
|| have_sub_uids(name, suid, 1))
Expand Down Expand Up @@ -216,7 +216,7 @@ static int user_busy_processes (const char *name, uid_t uid)
}

/* Check if the process is in our chroot */
stprintf_a(root_path, "/proc/%lu/root", (unsigned long) pid);
stprintf_a(root_path, "/proc/%d/root", pid);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commit 4 ("lib: apply linux specific pid_t format consistently"):

Reviewed-by: Alejandro Colomar <alx@kernel.org>

Thanks!

if (stat (root_path, &sbroot_process) != 0) {
continue;
}
Expand All @@ -225,7 +225,7 @@ static int user_busy_processes (const char *name, uid_t uid)
continue;
}

if (check_status (name, tmp_d_name, uid) != 0) {
if (check_status (name, uid, pid, pid) != 0) {
(void) closedir (proc);
#ifdef ENABLE_SUBIDS
sub_uid_close(true);
Expand All @@ -236,7 +236,7 @@ static int user_busy_processes (const char *name, uid_t uid)
return 1;
}

stprintf_a(task_path, "/proc/%lu/task", (unsigned long) pid);
stprintf_a(task_path, "/proc/%d/task", pid);
task_dir = opendir (task_path);
if (task_dir != NULL) {
while (NULL != (ent = readdir(task_dir))) {
Expand All @@ -247,7 +247,7 @@ static int user_busy_processes (const char *name, uid_t uid)
if (tid == pid) {
continue;
}
if (check_status (name, task_path+6, uid) != 0) {
if (check_status (name, uid, pid, tid) != 0) {
(void) closedir (proc);
(void) closedir (task_dir);
#ifdef ENABLE_SUBIDS
Expand All @@ -272,4 +272,3 @@ static int user_busy_processes (const char *name, uid_t uid)
return 0;
}
#endif /* __linux__ */

1 change: 1 addition & 0 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ test_snprintf_SOURCES = \
$(NULL)
test_snprintf_CFLAGS = \
$(AM_CFLAGS) \
-Wno-format-zero-length \
$(NULL)
test_snprintf_LDFLAGS = \
$(NULL)
Expand Down