diff options
author | Yi Zhao <yi.zhao@eng.windriver.com> | 2025-03-24 16:03:23 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-03-24 17:29:16 +0000 |
commit | d4993c837ac8b76a7644d41479bdc76f2fe39d41 (patch) | |
tree | 9b9a26de7f1ba11ce164d2ea20645721a12466ca | |
parent | 0834a9cdf684fc906f5afb20493579324cedea7b (diff) | |
download | poky-d4993c837ac8b76a7644d41479bdc76f2fe39d41.tar.gz |
coreutils: fix segfault for ls --context
Backport a patch to fix crash for ls --context when enable selinux:
root@qemux86-64:~# ls -Z /home
Segmentation fault (core dumped)
(From OE-Core rev: 414c7767fbfecf3afa4e64e8e3f50d56b6a65310)
Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-core/coreutils/coreutils/0001-ls-fix-crash-with-context.patch | 101 | ||||
-rw-r--r-- | meta/recipes-core/coreutils/coreutils_9.6.bb | 1 |
2 files changed, 102 insertions, 0 deletions
diff --git a/meta/recipes-core/coreutils/coreutils/0001-ls-fix-crash-with-context.patch b/meta/recipes-core/coreutils/coreutils/0001-ls-fix-crash-with-context.patch new file mode 100644 index 0000000000..b1a92875a6 --- /dev/null +++ b/meta/recipes-core/coreutils/coreutils/0001-ls-fix-crash-with-context.patch | |||
@@ -0,0 +1,101 @@ | |||
1 | From 43a63408630e5064317823702518099f0ea652dd Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com> | ||
3 | Date: Fri, 17 Jan 2025 17:29:34 +0000 | ||
4 | Subject: [PATCH] ls: fix crash with --context | ||
5 | |||
6 | * src/ls.c (main): Flag that we need to stat() | ||
7 | if we're going to get security context (call file_has_aclinfo_cache). | ||
8 | (file_has_aclinfo_cache): Be defensive and only lookup the device | ||
9 | for the file if the stat has been performed. | ||
10 | (has_capability_cache): Likewise. | ||
11 | * tests/ls/selinux-segfault.sh: Add a test case. | ||
12 | * NEWS: Mention the bug fix. | ||
13 | Reported by Bruno Haible. | ||
14 | |||
15 | Upstream-Status: Backport | ||
16 | [https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=915004f403cb25fadb207ddfdbe6a2f43bd44fac] | ||
17 | |||
18 | Signed-off-by: Yi Zhao <yi.zhao@windriver.com> | ||
19 | --- | ||
20 | NEWS | 3 +++ | ||
21 | src/ls.c | 10 +++++----- | ||
22 | tests/ls/selinux-segfault.sh | 3 +++ | ||
23 | 3 files changed, 11 insertions(+), 5 deletions(-) | ||
24 | |||
25 | diff --git a/NEWS b/NEWS | ||
26 | index 3799f75..65867f9 100644 | ||
27 | --- a/NEWS | ||
28 | +++ b/NEWS | ||
29 | @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*- | ||
30 | |||
31 | ** Bug fixes | ||
32 | |||
33 | + `ls -Z dir` would crash. | ||
34 | + [bug introduced in coreutils-9.6] | ||
35 | + | ||
36 | cp fixes support for --update=none-fail, which would have been | ||
37 | rejected as an invalid option. | ||
38 | [bug introduced in coreutils-9.5] | ||
39 | diff --git a/src/ls.c b/src/ls.c | ||
40 | index 3215360..f67167f 100644 | ||
41 | --- a/src/ls.c | ||
42 | +++ b/src/ls.c | ||
43 | @@ -1768,7 +1768,7 @@ main (int argc, char **argv) | ||
44 | |||
45 | format_needs_stat = ((sort_type == sort_time) | (sort_type == sort_size) | ||
46 | | (format == long_format) | ||
47 | - | print_block_size | print_hyperlink); | ||
48 | + | print_block_size | print_hyperlink | print_scontext); | ||
49 | format_needs_type = ((! format_needs_stat) | ||
50 | & (recursive | print_with_color | print_scontext | ||
51 | | directories_first | ||
52 | @@ -3309,7 +3309,7 @@ file_has_aclinfo_cache (char const *file, struct fileinfo *f, | ||
53 | static int unsupported_scontext_err; | ||
54 | static dev_t unsupported_device; | ||
55 | |||
56 | - if (f->stat.st_dev == unsupported_device) | ||
57 | + if (f->stat_ok && f->stat.st_dev == unsupported_device) | ||
58 | { | ||
59 | ai->buf = ai->u.__gl_acl_ch; | ||
60 | ai->size = 0; | ||
61 | @@ -3322,7 +3322,7 @@ file_has_aclinfo_cache (char const *file, struct fileinfo *f, | ||
62 | errno = 0; | ||
63 | int n = file_has_aclinfo (file, ai, flags); | ||
64 | int err = errno; | ||
65 | - if (n <= 0 && !acl_errno_valid (err)) | ||
66 | + if (f->stat_ok && n <= 0 && !acl_errno_valid (err)) | ||
67 | { | ||
68 | unsupported_return = n; | ||
69 | unsupported_scontext = ai->scontext; | ||
70 | @@ -3342,14 +3342,14 @@ has_capability_cache (char const *file, struct fileinfo *f) | ||
71 | found that has_capability fails indicating lack of support. */ | ||
72 | static dev_t unsupported_device; | ||
73 | |||
74 | - if (f->stat.st_dev == unsupported_device) | ||
75 | + if (f->stat_ok && f->stat.st_dev == unsupported_device) | ||
76 | { | ||
77 | errno = ENOTSUP; | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | bool b = has_capability (file); | ||
82 | - if ( !b && !acl_errno_valid (errno)) | ||
83 | + if (f->stat_ok && !b && !acl_errno_valid (errno)) | ||
84 | unsupported_device = f->stat.st_dev; | ||
85 | return b; | ||
86 | } | ||
87 | diff --git a/tests/ls/selinux-segfault.sh b/tests/ls/selinux-segfault.sh | ||
88 | index 11623ac..1cac2b5 100755 | ||
89 | --- a/tests/ls/selinux-segfault.sh | ||
90 | +++ b/tests/ls/selinux-segfault.sh | ||
91 | @@ -30,4 +30,7 @@ mkdir sedir || framework_failure_ | ||
92 | ln -sf missing sedir/broken || framework_failure_ | ||
93 | returns_ 1 ls -L -R -Z -m sedir > out || fail=1 | ||
94 | |||
95 | +# ls 9.6 would segfault with the following | ||
96 | +ls -Z . > out || fail=1 | ||
97 | + | ||
98 | Exit $fail | ||
99 | -- | ||
100 | 2.34.1 | ||
101 | |||
diff --git a/meta/recipes-core/coreutils/coreutils_9.6.bb b/meta/recipes-core/coreutils/coreutils_9.6.bb index 17bd33958b..6db435cfcb 100644 --- a/meta/recipes-core/coreutils/coreutils_9.6.bb +++ b/meta/recipes-core/coreutils/coreutils_9.6.bb | |||
@@ -17,6 +17,7 @@ SRC_URI = "${GNU_MIRROR}/coreutils/${BP}.tar.xz \ | |||
17 | file://remove-usr-local-lib-from-m4.patch \ | 17 | file://remove-usr-local-lib-from-m4.patch \ |
18 | file://0001-local.mk-fix-cross-compiling-problem.patch \ | 18 | file://0001-local.mk-fix-cross-compiling-problem.patch \ |
19 | file://intermittent-testfailure.patch \ | 19 | file://intermittent-testfailure.patch \ |
20 | file://0001-ls-fix-crash-with-context.patch \ | ||
20 | file://run-ptest \ | 21 | file://run-ptest \ |
21 | " | 22 | " |
22 | SRC_URI[sha256sum] = "7a0124327b398fd9eb1a6abde583389821422c744ffa10734b24f557610d3283" | 23 | SRC_URI[sha256sum] = "7a0124327b398fd9eb1a6abde583389821422c744ffa10734b24f557610d3283" |