cpio: patch CVE-2026-66485

Pick patch mentioned in NVD CVE description.

(From OE-Core rev: 090d104c522f4d1c3b99ab29f8214a1e14c3e36e)

Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(From OE-Core rev: c105fbf82e2f50b05dc680e0601bf0ea3198e58c)
Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Paul Barker <paul@pbarker.dev>
This commit is contained in:
Peter Marko authored and Paul Barker committed 2026-09-28 10:17:42 +01:00
1 parent a004a41739
commit 5e5ced9b00
2 files changed
+211

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=f27defe1e96c2e1ecd4e0c9be8967949"
SRC_URI = "${GNU_MIRROR}/cpio/cpio-${PV}.tar.gz \
file://run-ptest \
file://test.sh \
file://CVE-2026-66485.patch \
"
SRC_URI[sha256sum] = "efa50ef983137eefc0a02fdb51509d624b5e3295c980aa127ceee4183455499e"
@@ -0,0 +1,210 @@
From 3cd514031371d8aeeaf2048aa10103e02831aaa9 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Fri, 1 May 2026 08:19:41 +0300
Subject: [PATCH] Minor fixes
* src/makepath.c: Don't use alloca.
* src/userspec.c: Likewise.
CVE: CVE-2026-66485
Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=3cd514031371d8aeeaf2048aa10103e02831aaa9]
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
src/makepath.c | 31 ++++++++++++++---------
src/userspec.c | 67 +++++++++++++++++++++++++-------------------------
2 files changed, 53 insertions(+), 45 deletions(-)
diff --git a/src/makepath.c b/src/makepath.c
index 35dbc73..c6329bf 100644
--- a/src/makepath.c
+++ b/src/makepath.c
@@ -47,24 +47,19 @@
Return 0 if ARGPATH exists as a directory with the proper
ownership and permissions when done, otherwise 1. */
-int
-make_path (char const *argpath,
- uid_t owner,
- gid_t group,
- const char *verbose_fmt_string)
+static int
+make_path0 (char *dirpath,
+ uid_t owner,
+ gid_t group,
+ const char *verbose_fmt_string)
{
- char *dirpath; /* A copy we can scribble NULs on. */
struct stat stats;
- int retval = 0;
mode_t tmpmode;
mode_t invert_permissions;
int we_are_root = getuid () == 0;
- dirpath = alloca (strlen (argpath) + 1);
-
- strcpy (dirpath, argpath);
if (stat (dirpath, &stats))
- {
+ {
tmpmode = MODE_RWX & ~ newdir_umask;
invert_permissions = we_are_root ? 0 : MODE_WXUSR & ~ tmpmode;
@@ -157,5 +152,19 @@ make_path (char const *argpath,
}
+ return 0;
+}
+
+int
+make_path (char const *argpath,
+ uid_t owner,
+ gid_t group,
+ const char *verbose_fmt_string)
+{
+ char *dirpath = xstrdup (argpath);
+ int retval = make_path0 (dirpath, owner, group, verbose_fmt_string);
+ free (dirpath);
return retval;
}
+
+
diff --git a/src/userspec.c b/src/userspec.c
index 2a2b324..1a2bfa0 100644
--- a/src/userspec.c
+++ b/src/userspec.c
@@ -19,7 +19,6 @@
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <system.h>
-#include <alloca.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
@@ -33,18 +32,6 @@
# define endgrent()
#endif
-/* Perform the equivalent of the statement `dest = strdup (src);',
- but obtaining storage via alloca instead of from the heap. */
-
-#define V_STRDUP(dest, src) \
- do \
- { \
- int _len = strlen ((src)); \
- (dest) = (char *) alloca (_len + 1); \
- strcpy (dest, src); \
- } \
- while (0)
-
/* Return nonzero if STR represents an unsigned decimal integer,
otherwise return 0. */
@@ -57,6 +44,18 @@ isnumber_p (const char *str)
return 1;
}
+static void
+store_string (char **bufptr, size_t *buflen, char *str)
+{
+ size_t len = strlen (str) + 1;
+ if (len > *buflen)
+ {
+ *bufptr = xrealloc (*bufptr, len);
+ *buflen = len;
+ }
+ strcpy (*bufptr, str);
+}
+
/* Extract from NAME, which has the form "[user][:.][group]",
a USERNAME, UID U, GROUPNAME, and GID G.
Either user or group, or both, must be present.
@@ -70,23 +69,21 @@ isnumber_p (const char *str)
Return NULL if successful, a static error message string if not. */
const char *
-parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
- char **username_arg, char **groupname_arg)
+parse_user_spec0 (char *spec, uid_t *uid, gid_t *gid,
+ char **username_arg, char **groupname_arg)
{
static const char *tired = "virtual memory exhausted";
const char *error_msg;
- char *spec; /* A copy we can write on. */
struct passwd *pwd;
struct group *grp;
char *g, *u, *separator;
- char *groupname;
+ char *groupname = NULL;
+ size_t grouplen = 0;
error_msg = NULL;
*username_arg = *groupname_arg = NULL;
groupname = NULL;
- V_STRDUP (spec, spec_arg);
-
/* Find the separator if there is one. */
separator = strchr (spec, ':');
if (separator == NULL)
@@ -143,11 +140,12 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
if (grp == NULL)
{
char nbuf[UINTMAX_STRSIZE_BOUND];
- V_STRDUP (groupname, umaxtostr (pwd->pw_gid, nbuf));
+ store_string (&groupname, &grouplen,
+ umaxtostr (pwd->pw_gid, nbuf));
}
else
{
- V_STRDUP (groupname, grp->gr_name);
+ store_string (&groupname, &grouplen, grp->gr_name);
}
endgrent ();
}
@@ -178,7 +176,7 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
endgrent (); /* Save a file descriptor. */
if (error_msg == NULL)
- V_STRDUP (groupname, g);
+ store_string (&groupname, &grouplen, g);
}
if (error_msg == NULL)
@@ -191,23 +189,24 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
}
if (groupname != NULL && error_msg == NULL)
- {
- *groupname_arg = strdup (groupname);
- if (*groupname_arg == NULL)
- {
- if (*username_arg != NULL)
- {
- free (*username_arg);
- *username_arg = NULL;
- }
- error_msg = tired;
- }
- }
+ *groupname_arg = groupname;
}
+ else
+ free (groupname);
return error_msg;
}
+const char *
+parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
+ char **username, char **groupname)
+{
+ char *spec = xstrdup (spec_arg);
+ const char *retval = parse_user_spec0 (spec, uid, gid, username, groupname);
+ free (spec);
+ return retval;
+}
+
#ifdef TEST
#define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s))