|
|
51d9a3 |
From 960e78f208b4f6d48962bbc9cad45588cc8c90ad Mon Sep 17 00:00:00 2001
|
|
|
51d9a3 |
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
|
|
51d9a3 |
Date: Tue, 21 Jun 2022 08:43:00 +0200
|
|
|
51d9a3 |
Subject: [PATCH] secontext: print context of Unix socket's sun_path field
|
|
|
51d9a3 |
MIME-Version: 1.0
|
|
|
51d9a3 |
Content-Type: text/plain; charset=UTF-8
|
|
|
51d9a3 |
Content-Transfer-Encoding: 8bit
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
* src/sockaddr.c: Include "secontext.h".
|
|
|
51d9a3 |
(print_sockaddr_data_un): Print the SELinux context of sun_path field
|
|
|
51d9a3 |
using selinux_printfilecon.
|
|
|
51d9a3 |
* NEWS: Mention this change.
|
|
|
51d9a3 |
* tests/secontext.c (raw_secontext_full_fd, get_secontext_field_fd,
|
|
|
51d9a3 |
raw_secontext_short_fd, secontext_full_fd, secontext_short_fd): New
|
|
|
51d9a3 |
functions.
|
|
|
51d9a3 |
* tests/secontext.h (secontext_full_fd, secontext_short_fd,
|
|
|
51d9a3 |
get_secontext_field_fd): New prototypes.
|
|
|
51d9a3 |
(SECONTEXT_FD): New macro.
|
|
|
51d9a3 |
* tests/sockname.c: Include "secontext.h".
|
|
|
51d9a3 |
(test_sockname_syscall): Update expected output.
|
|
|
51d9a3 |
* tests/gen_tests.in (getsockname--secontext,
|
|
|
51d9a3 |
getsockname--secontext_full, getsockname--secontext_full_mismatch,
|
|
|
51d9a3 |
getsockname--secontext_mismatch): New tests.
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Resolves: https://github.com/strace/strace/pull/214
|
|
|
51d9a3 |
---
|
|
|
51d9a3 |
NEWS | 1 +
|
|
|
51d9a3 |
src/sockaddr.c | 3 +++
|
|
|
51d9a3 |
tests/gen_tests.in | 4 ++++
|
|
|
51d9a3 |
tests/secontext.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
51d9a3 |
tests/secontext.h | 12 ++++++++++++
|
|
|
51d9a3 |
tests/sockname.c | 54 +++++++++++++++++++++++++++++++++++-------------------
|
|
|
51d9a3 |
6 files changed, 104 insertions(+), 19 deletions(-)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Index: strace-5.18/NEWS
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/NEWS 2022-07-12 18:20:18.495470531 +0200
|
|
|
51d9a3 |
+++ strace-5.18/NEWS 2022-07-12 18:20:44.531163262 +0200
|
|
|
51d9a3 |
@@ -5,6 +5,7 @@
|
|
|
51d9a3 |
* Added an interface of raising des Strausses awareness.
|
|
|
51d9a3 |
* Added --tips option to print strace tips, tricks, and tweaks
|
|
|
51d9a3 |
at the end of the tracing session.
|
|
|
51d9a3 |
+ * Implemented printing of Unix socket sun_path field's SELinux context.
|
|
|
51d9a3 |
* Enhanced decoding of bpf and io_uring_register syscalls.
|
|
|
51d9a3 |
* Implemented decoding of COUNTER_*, RTC_PARAM_GET, and RTC_PARAM_SET ioctl
|
|
|
51d9a3 |
commands.
|
|
|
51d9a3 |
Index: strace-5.18/src/sockaddr.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/src/sockaddr.c 2022-07-12 18:17:36.745379483 +0200
|
|
|
51d9a3 |
+++ strace-5.18/src/sockaddr.c 2022-07-12 18:20:18.495470531 +0200
|
|
|
51d9a3 |
@@ -63,6 +63,8 @@
|
|
|
51d9a3 |
#include "xlat/mctp_addrs.h"
|
|
|
51d9a3 |
#include "xlat/mctp_nets.h"
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+#include "secontext.h"
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
#define SIZEOF_SA_FAMILY sizeof_field(struct sockaddr, sa_family)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
struct sockaddr_rxrpc {
|
|
|
51d9a3 |
@@ -115,6 +117,7 @@
|
|
|
51d9a3 |
if (sa_un->sun_path[0]) {
|
|
|
51d9a3 |
print_quoted_string(sa_un->sun_path, path_len + 1,
|
|
|
51d9a3 |
QUOTE_0_TERMINATED);
|
|
|
51d9a3 |
+ selinux_printfilecon(tcp, sa_un->sun_path);
|
|
|
51d9a3 |
} else {
|
|
|
51d9a3 |
tprints("@");
|
|
|
51d9a3 |
print_quoted_string(sa_un->sun_path + 1, path_len - 1, 0);
|
|
|
51d9a3 |
Index: strace-5.18/tests/gen_tests.in
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests/gen_tests.in 2022-07-12 18:17:36.746379471 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests/gen_tests.in 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -225,6 +225,10 @@
|
|
|
51d9a3 |
getsid -a10
|
|
|
51d9a3 |
getsid--pidns-translation test_pidns -e trace=getsid -a10
|
|
|
51d9a3 |
getsockname -a27
|
|
|
51d9a3 |
+getsockname--secontext -a27 --secontext -e trace=getsockname
|
|
|
51d9a3 |
+getsockname--secontext_full -a27 --secontext=full -e trace=getsockname
|
|
|
51d9a3 |
+getsockname--secontext_full_mismatch -a27 --secontext=full,mismatch -e trace=getsockname
|
|
|
51d9a3 |
+getsockname--secontext_mismatch -a27 --secontext=mismatch -e trace=getsockname
|
|
|
51d9a3 |
gettid -a9
|
|
|
51d9a3 |
getuid-creds +getuid.test
|
|
|
51d9a3 |
getuid32 +getuid.test
|
|
|
51d9a3 |
Index: strace-5.18/tests/secontext.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests/secontext.c 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests/secontext.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -141,6 +141,21 @@
|
|
|
51d9a3 |
return full_secontext;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
+raw_secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *full_secontext = NULL;
|
|
|
51d9a3 |
+ char *secontext;
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ if (fgetfilecon(fd, &secontext) >= 0) {
|
|
|
51d9a3 |
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
|
|
|
51d9a3 |
+ freecon(secontext);
|
|
|
51d9a3 |
+ }
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return full_secontext;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -151,6 +166,16 @@
|
|
|
51d9a3 |
return type;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ char *ctx = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ char *type = get_secontext_field(ctx, field);
|
|
|
51d9a3 |
+ free(ctx);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ return type;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
raw_secontext_short_file(const char *filename)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -158,6 +183,12 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
+raw_secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
raw_secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
int saved_errno = errno;
|
|
|
51d9a3 |
@@ -205,6 +236,15 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
+secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
|
|
|
51d9a3 |
@@ -228,6 +268,15 @@
|
|
|
51d9a3 |
errno = saved_errno;
|
|
|
51d9a3 |
return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_short_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
secontext_short_pid(pid_t pid)
|
|
|
51d9a3 |
Index: strace-5.18/tests/secontext.h
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests/secontext.h 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests/secontext.h 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -9,9 +9,11 @@
|
|
|
51d9a3 |
#include "xmalloc.h"
|
|
|
51d9a3 |
#include <unistd.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
@@ -30,6 +32,7 @@
|
|
|
51d9a3 |
*/
|
|
|
51d9a3 |
char *get_secontext_field(const char *full_context, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *get_secontext_field_fd(int fd, enum secontext_field field);
|
|
|
51d9a3 |
char *get_secontext_field_file(const char *file, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
void reset_secontext_file(const char *file);
|
|
|
51d9a3 |
@@ -44,6 +47,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
@@ -53,6 +57,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
@@ -65,6 +70,12 @@
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
static inline char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return NULL;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static inline char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
@@ -81,6 +92,7 @@
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) xstrdup("")
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Index: strace-5.18/tests/sockname.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests/sockname.c 2022-07-12 18:17:36.748379448 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests/sockname.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -18,6 +18,8 @@
|
|
|
51d9a3 |
#include <sys/socket.h>
|
|
|
51d9a3 |
#include <sys/un.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+#include "secontext.h"
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
#ifndef TEST_SYSCALL_NAME
|
|
|
51d9a3 |
# error TEST_SYSCALL_NAME must be defined
|
|
|
51d9a3 |
#endif
|
|
|
51d9a3 |
@@ -59,14 +61,19 @@
|
|
|
51d9a3 |
*plen = sizeof(struct sockaddr_un);
|
|
|
51d9a3 |
struct sockaddr_un *addr = tail_alloc(*plen);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+ char *my_secontext = SECONTEXT_PID_MY();
|
|
|
51d9a3 |
+ char *fd_secontext = SECONTEXT_FD(fd);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
memset(addr, 0, sizeof(*addr));
|
|
|
51d9a3 |
@@ -75,28 +82,34 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
|
|
|
51d9a3 |
- sprintrc(rc));
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
|
|
|
51d9a3 |
+ addr, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext,
|
|
|
51d9a3 |
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen + 1 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
plen + 1, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
|
|
|
51d9a3 |
@@ -108,8 +121,9 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
++addr;
|
|
|
51d9a3 |
@@ -121,17 +135,19 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
|
|
|
51d9a3 |
- addr->sun_path, (int) sizeof(struct sockaddr),
|
|
|
51d9a3 |
- (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
*plen, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
Index: strace-5.18/tests-m32/secontext.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-m32/secontext.c 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-m32/secontext.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -141,6 +141,21 @@
|
|
|
51d9a3 |
return full_secontext;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
+raw_secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *full_secontext = NULL;
|
|
|
51d9a3 |
+ char *secontext;
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ if (fgetfilecon(fd, &secontext) >= 0) {
|
|
|
51d9a3 |
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
|
|
|
51d9a3 |
+ freecon(secontext);
|
|
|
51d9a3 |
+ }
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return full_secontext;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -151,6 +166,16 @@
|
|
|
51d9a3 |
return type;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ char *ctx = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ char *type = get_secontext_field(ctx, field);
|
|
|
51d9a3 |
+ free(ctx);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ return type;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
raw_secontext_short_file(const char *filename)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -158,6 +183,12 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
+raw_secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
raw_secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
int saved_errno = errno;
|
|
|
51d9a3 |
@@ -205,6 +236,15 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
+secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
|
|
|
51d9a3 |
@@ -228,6 +268,15 @@
|
|
|
51d9a3 |
errno = saved_errno;
|
|
|
51d9a3 |
return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_short_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
secontext_short_pid(pid_t pid)
|
|
|
51d9a3 |
Index: strace-5.18/tests-m32/secontext.h
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-m32/secontext.h 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-m32/secontext.h 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -9,9 +9,11 @@
|
|
|
51d9a3 |
#include "xmalloc.h"
|
|
|
51d9a3 |
#include <unistd.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
@@ -30,6 +32,7 @@
|
|
|
51d9a3 |
*/
|
|
|
51d9a3 |
char *get_secontext_field(const char *full_context, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *get_secontext_field_fd(int fd, enum secontext_field field);
|
|
|
51d9a3 |
char *get_secontext_field_file(const char *file, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
void reset_secontext_file(const char *file);
|
|
|
51d9a3 |
@@ -44,6 +47,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
@@ -53,6 +57,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
@@ -65,6 +70,12 @@
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
static inline char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return NULL;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static inline char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
@@ -81,6 +92,7 @@
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) xstrdup("")
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Index: strace-5.18/tests-m32/sockname.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-m32/sockname.c 2022-07-12 18:17:36.748379448 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-m32/sockname.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -18,6 +18,8 @@
|
|
|
51d9a3 |
#include <sys/socket.h>
|
|
|
51d9a3 |
#include <sys/un.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+#include "secontext.h"
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
#ifndef TEST_SYSCALL_NAME
|
|
|
51d9a3 |
# error TEST_SYSCALL_NAME must be defined
|
|
|
51d9a3 |
#endif
|
|
|
51d9a3 |
@@ -59,14 +61,19 @@
|
|
|
51d9a3 |
*plen = sizeof(struct sockaddr_un);
|
|
|
51d9a3 |
struct sockaddr_un *addr = tail_alloc(*plen);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+ char *my_secontext = SECONTEXT_PID_MY();
|
|
|
51d9a3 |
+ char *fd_secontext = SECONTEXT_FD(fd);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
memset(addr, 0, sizeof(*addr));
|
|
|
51d9a3 |
@@ -75,28 +82,34 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
|
|
|
51d9a3 |
- sprintrc(rc));
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
|
|
|
51d9a3 |
+ addr, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext,
|
|
|
51d9a3 |
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen + 1 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
plen + 1, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
|
|
|
51d9a3 |
@@ -108,8 +121,9 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
++addr;
|
|
|
51d9a3 |
@@ -121,17 +135,19 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
|
|
|
51d9a3 |
- addr->sun_path, (int) sizeof(struct sockaddr),
|
|
|
51d9a3 |
- (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
*plen, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
Index: strace-5.18/tests-mx32/secontext.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-mx32/secontext.c 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-mx32/secontext.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -141,6 +141,21 @@
|
|
|
51d9a3 |
return full_secontext;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
+raw_secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *full_secontext = NULL;
|
|
|
51d9a3 |
+ char *secontext;
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ if (fgetfilecon(fd, &secontext) >= 0) {
|
|
|
51d9a3 |
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
|
|
|
51d9a3 |
+ freecon(secontext);
|
|
|
51d9a3 |
+ }
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return full_secontext;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -151,6 +166,16 @@
|
|
|
51d9a3 |
return type;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ char *ctx = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ char *type = get_secontext_field(ctx, field);
|
|
|
51d9a3 |
+ free(ctx);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+ return type;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
raw_secontext_short_file(const char *filename)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
@@ -158,6 +183,12 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
static char *
|
|
|
51d9a3 |
+raw_secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static char *
|
|
|
51d9a3 |
raw_secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
int saved_errno = errno;
|
|
|
51d9a3 |
@@ -205,6 +236,15 @@
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
+secontext_full_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_full_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
secontext_full_pid(pid_t pid)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
|
|
|
51d9a3 |
@@ -228,6 +268,15 @@
|
|
|
51d9a3 |
errno = saved_errno;
|
|
|
51d9a3 |
return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+char *
|
|
|
51d9a3 |
+secontext_short_fd(int fd)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ int saved_errno = errno;
|
|
|
51d9a3 |
+ char *context = raw_secontext_short_fd(fd);
|
|
|
51d9a3 |
+ errno = saved_errno;
|
|
|
51d9a3 |
+ return FORMAT_SPACE_BEFORE(context);
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
char *
|
|
|
51d9a3 |
secontext_short_pid(pid_t pid)
|
|
|
51d9a3 |
Index: strace-5.18/tests-mx32/secontext.h
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-mx32/secontext.h 2022-07-12 18:17:36.747379459 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-mx32/secontext.h 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -9,9 +9,11 @@
|
|
|
51d9a3 |
#include "xmalloc.h"
|
|
|
51d9a3 |
#include <unistd.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
|
|
|
51d9a3 |
|
|
|
51d9a3 |
@@ -30,6 +32,7 @@
|
|
|
51d9a3 |
*/
|
|
|
51d9a3 |
char *get_secontext_field(const char *full_context, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+char *get_secontext_field_fd(int fd, enum secontext_field field);
|
|
|
51d9a3 |
char *get_secontext_field_file(const char *file, enum secontext_field field);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
void reset_secontext_file(const char *file);
|
|
|
51d9a3 |
@@ -44,6 +47,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
@@ -53,6 +57,7 @@
|
|
|
51d9a3 |
# else
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
|
|
|
51d9a3 |
|
|
|
51d9a3 |
# endif
|
|
|
51d9a3 |
@@ -65,6 +70,12 @@
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
static inline char *
|
|
|
51d9a3 |
+get_secontext_field_fd(int fd, enum secontext_field field)
|
|
|
51d9a3 |
+{
|
|
|
51d9a3 |
+ return NULL;
|
|
|
51d9a3 |
+}
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
+static inline char *
|
|
|
51d9a3 |
get_secontext_field_file(const char *file, enum secontext_field field)
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
return NULL;
|
|
|
51d9a3 |
@@ -81,6 +92,7 @@
|
|
|
51d9a3 |
{
|
|
|
51d9a3 |
}
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+# define SECONTEXT_FD(fd) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_FILE(filename) xstrdup("")
|
|
|
51d9a3 |
# define SECONTEXT_PID(pid) xstrdup("")
|
|
|
51d9a3 |
|
|
|
51d9a3 |
Index: strace-5.18/tests-mx32/sockname.c
|
|
|
51d9a3 |
===================================================================
|
|
|
51d9a3 |
--- strace-5.18.orig/tests-mx32/sockname.c 2022-07-12 18:17:36.748379448 +0200
|
|
|
51d9a3 |
+++ strace-5.18/tests-mx32/sockname.c 2022-07-12 18:20:18.496470519 +0200
|
|
|
51d9a3 |
@@ -18,6 +18,8 @@
|
|
|
51d9a3 |
#include <sys/socket.h>
|
|
|
51d9a3 |
#include <sys/un.h>
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+#include "secontext.h"
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
#ifndef TEST_SYSCALL_NAME
|
|
|
51d9a3 |
# error TEST_SYSCALL_NAME must be defined
|
|
|
51d9a3 |
#endif
|
|
|
51d9a3 |
@@ -59,14 +61,19 @@
|
|
|
51d9a3 |
*plen = sizeof(struct sockaddr_un);
|
|
|
51d9a3 |
struct sockaddr_un *addr = tail_alloc(*plen);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
+ char *my_secontext = SECONTEXT_PID_MY();
|
|
|
51d9a3 |
+ char *fd_secontext = SECONTEXT_FD(fd);
|
|
|
51d9a3 |
+
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
memset(addr, 0, sizeof(*addr));
|
|
|
51d9a3 |
@@ -75,28 +82,34 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
|
|
|
51d9a3 |
", [%d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
(int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
|
|
|
51d9a3 |
- sprintrc(rc));
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
|
|
|
51d9a3 |
+ addr, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext,
|
|
|
51d9a3 |
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
|
|
|
51d9a3 |
SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen + 1 SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
plen + 1, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
|
|
|
51d9a3 |
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
|
|
|
51d9a3 |
@@ -108,8 +121,9 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
++addr;
|
|
|
51d9a3 |
@@ -121,17 +135,19 @@
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
if (rc < 0)
|
|
|
51d9a3 |
perror_msg_and_skip(TEST_SYSCALL_STR);
|
|
|
51d9a3 |
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
|
|
|
51d9a3 |
", [%d => %d]%s) = %d\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
|
|
|
51d9a3 |
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
|
|
|
51d9a3 |
- addr->sun_path, (int) sizeof(struct sockaddr),
|
|
|
51d9a3 |
- (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
|
|
|
51d9a3 |
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
|
|
|
51d9a3 |
|
|
|
51d9a3 |
PREPARE_TEST_SYSCALL_INVOCATION;
|
|
|
51d9a3 |
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
|
|
|
51d9a3 |
plen SUFFIX_ARGS);
|
|
|
51d9a3 |
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
|
|
|
51d9a3 |
+ my_secontext,
|
|
|
51d9a3 |
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
|
|
|
51d9a3 |
*plen, SUFFIX_STR, sprintrc(rc));
|
|
|
51d9a3 |
}
|