summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Doshi <sdoshi@mvista.com>2024-06-13 20:15:40 +0530
committerArmin Kuster <akuster808@gmail.com>2024-06-27 11:25:07 -0400
commit6e72002046997036981c01da5acba13656029f4c (patch)
tree5e8f47bd1778d333bcb09a2d68a30663fa3f5d32
parent23398704b5a17f835882fc2a0cd8a134a544c7bc (diff)
downloadmeta-openembedded-6e72002046997036981c01da5acba13656029f4c.tar.gz
nano: Security fix for CVE-2024-5742
Upstream-Status: Backport from [https://git.savannah.gnu.org/cgit/nano.git/commit/?id=5e7a3c2e7e118c7f12d5dfda9f9140f638976aa2] CVE's Fixed: CVE-2024-5742 nano: running `chmod` and `chown` on the filename allows malicious user to replace the emergency file with a malicious symlink to a root-owned file Signed-off-by: Siddharth Doshi <sdoshi@mvista.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r--meta-oe/recipes-support/nano/files/CVE-2024-5742.patch100
-rw-r--r--meta-oe/recipes-support/nano/nano_6.2.bb4
2 files changed, 103 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/nano/files/CVE-2024-5742.patch b/meta-oe/recipes-support/nano/files/CVE-2024-5742.patch
new file mode 100644
index 0000000000..64a395f2d2
--- /dev/null
+++ b/meta-oe/recipes-support/nano/files/CVE-2024-5742.patch
@@ -0,0 +1,100 @@
1From 5e7a3c2e7e118c7f12d5dfda9f9140f638976aa2 Mon Sep 17 00:00:00 2001
2From: Benno Schulenberg <bensberg@telfort.nl>
3Date: Sun, 28 Apr 2024 10:51:52 +0200
4Subject: files: run `chmod` and `chown` on the descriptor, not on the filename
5
6This closes a window of opportunity where the emergency file could be
7replaced by a malicious symlink.
8
9The issue was reported by `MartinJM` and `InvisibleMeerkat`.
10
11Problem existed since version 2.2.0, commit 123110c5, when chmodding
12and chowning of the emergency .save file was added.
13
14Upstream-Status: Backport from [https://git.savannah.gnu.org/cgit/nano.git/commit/?id=5e7a3c2e7e118c7f12d5dfda9f9140f638976aa2]
15CVE: CVE-2024-5742
16Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
17---
18 src/definitions.h | 2 +-
19 src/files.c | 13 ++++++++++++-
20 src/nano.c | 12 +-----------
21 3 files changed, 14 insertions(+), 13 deletions(-)
22
23diff --git a/src/definitions.h b/src/definitions.h
24index 2bdc782..e9d0de3 100644
25--- a/src/definitions.h
26+++ b/src/definitions.h
27@@ -277,7 +277,7 @@ typedef enum {
28 } message_type;
29
30 typedef enum {
31- OVERWRITE, APPEND, PREPEND
32+ OVERWRITE, APPEND, PREPEND, EMERGENCY
33 } kind_of_writing_type;
34
35 typedef enum {
36diff --git a/src/files.c b/src/files.c
37index 62cc8f2..c5527a6 100644
38--- a/src/files.c
39+++ b/src/files.c
40@@ -1760,6 +1760,8 @@ bool write_file(const char *name, FILE *thefile, bool normal,
41 #endif
42 char *realname = real_dir_from_tilde(name);
43 /* The filename after tilde expansion. */
44+ int fd = 0;
45+ /* The descriptor that is assigned when opening the file. */
46 char *tempname = NULL;
47 /* The name of the temporary file we use when prepending. */
48 linestruct *line = openfile->filetop;
49@@ -1843,7 +1845,6 @@ bool write_file(const char *name, FILE *thefile, bool normal,
50 * For an emergency file, access is restricted to just the owner. */
51 if (thefile == NULL) {
52 mode_t permissions = (normal ? RW_FOR_ALL : S_IRUSR|S_IWUSR);
53- int fd;
54
55 #ifndef NANO_TINY
56 block_sigwinch(TRUE);
57@@ -1970,6 +1971,16 @@ bool write_file(const char *name, FILE *thefile, bool normal,
58 }
59 #endif
60
61+#if !defined(NANO_TINY) && defined(HAVE_CHMOD) && defined(HAVE_CHOWN)
62+ /* Change permissions and owner of an emergency save file to the values
63+ * of the original file, but ignore any failure as we are in a hurry. */
64+ if (method == EMERGENCY && fd && openfile->statinfo) {
65+ IGNORE_CALL_RESULT(fchmod(fd, openfile->statinfo->st_mode));
66+ IGNORE_CALL_RESULT(fchown(fd, openfile->statinfo->st_uid,
67+ openfile->statinfo->st_gid));
68+ }
69+#endif
70+
71 if (fclose(thefile) != 0) {
72 statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
73
74diff --git a/src/nano.c b/src/nano.c
75index 04ecdbb..2ce3462 100644
76--- a/src/nano.c
77+++ b/src/nano.c
78@@ -337,18 +337,8 @@ void emergency_save(const char *filename)
79
80 if (*targetname == '\0')
81 fprintf(stderr, _("\nToo many .save files\n"));
82- else if (write_file(targetname, NULL, SPECIAL, OVERWRITE, NONOTES)) {
83+ else if (write_file(targetname, NULL, SPECIAL, EMERGENCY, NONOTES))
84 fprintf(stderr, _("\nBuffer written to %s\n"), targetname);
85-#ifndef NANO_TINY
86- /* Try to chmod/chown the saved file to the values of the original file,
87- * but ignore any failure as we are in a hurry to get out. */
88- if (openfile->statinfo) {
89- IGNORE_CALL_RESULT(chmod(targetname, openfile->statinfo->st_mode));
90- IGNORE_CALL_RESULT(chown(targetname, openfile->statinfo->st_uid,
91- openfile->statinfo->st_gid));
92- }
93-#endif
94- }
95
96 free(targetname);
97 free(plainname);
98--
992.35.7
100
diff --git a/meta-oe/recipes-support/nano/nano_6.2.bb b/meta-oe/recipes-support/nano/nano_6.2.bb
index 0be022467b..10e74869c1 100644
--- a/meta-oe/recipes-support/nano/nano_6.2.bb
+++ b/meta-oe/recipes-support/nano/nano_6.2.bb
@@ -12,7 +12,9 @@ RDEPENDS:${PN} = "ncurses-terminfo-base"
12 12
13PV_MAJOR = "${@d.getVar('PV').split('.')[0]}" 13PV_MAJOR = "${@d.getVar('PV').split('.')[0]}"
14 14
15SRC_URI = "https://nano-editor.org/dist/v${PV_MAJOR}/nano-${PV}.tar.xz" 15SRC_URI = "https://nano-editor.org/dist/v${PV_MAJOR}/nano-${PV}.tar.xz \
16 file://CVE-2024-5742.patch \
17 "
16SRC_URI[sha256sum] = "2bca1804bead6aaf4ad791f756e4749bb55ed860eec105a97fba864bc6a77cb3" 18SRC_URI[sha256sum] = "2bca1804bead6aaf4ad791f756e4749bb55ed860eec105a97fba864bc6a77cb3"
17 19
18UPSTREAM_CHECK_URI = "https://ftp.gnu.org/gnu/nano" 20UPSTREAM_CHECK_URI = "https://ftp.gnu.org/gnu/nano"