Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Danny Hu" <dannyhu@arista.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>
Cc: "Mimi Zohar" <zohar@linux.ibm.com>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
	"Eric Snowberg" <eric.snowberg@oracle.com>,
	"Jan Kara" <jack@suse.cz>, "Victor Kamensky" <kamensky@cisco.com>,
	"Taras Kondratiuk" <takondra@cisco.com>,
	"Tianxing Zhang" <zhangtianxing3@huawei.com>,
	"Zheng Zengkai" <zhengzengkai@huawei.com>,
	zhoushuiqing <zhoushuiqing2@huawei.com>,
	zhangguangzhi <zhangguangzhi3@huawei.com>,
	"Jason Yan" <yanaijie@huawei.com>,
	silviu.vlasceanu@huawei.com, hpa@zytor.com, arnd@arndb.de,
	rob@landley.net, james.w.mcmechan@gmail.com,
	niveditas98@gmail.com, pierre@arista.com, julien@arista.com,
	kbharathi@arista.com, erosca@de.adit-jv.com,
	alexandr.lobakin@intel.com, jim_baxter@mentor.com,
	linux-security-module@vger.kernel.org,
	linux-kbuild@vger.kernel.org, bug-cpio@gnu.org,
	nathan@kernel.org, nsc@kernel.org
Subject: Re: [PATCH v5 4/4] gen_init_cpio: add support for file metadata
Date: Sat, 31 Oct 2026 21:10:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-192153@kernel.org> (raw)
In-Reply-To: <20261030210944.2143778-5-dannyhu@arista.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] initramfs: NULL path passed to llistxattr() in write_xattrs()
- [Low] initramfs: undefined __packed macro in host tool usr/gen_init_cpio.c
--

commit f793fe8aaa70c6c2c7baf3bf7456e36e56bc7fcf
Author: Roberto Sassu <roberto.sassu@huawei.com>

gen_init_cpio: add support for file metadata

This commit adds support for including extended attribute (TYPE_XATTR) file
metadata in initramfs cpio archives as separate METADATA!!! entries when
configured via CONFIG_INITRAMFS_FILE_METADATA.

> diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
> index b7296edc6626f..f07be54c9219e 100644
> --- a/usr/gen_init_cpio.c
> +++ b/usr/gen_init_cpio.c
> @@ -6,6 +6,7 @@
>  #include <stdbool.h>
>  #include <sys/types.h>
>  #include <sys/stat.h>
> +#include <sys/xattr.h>
>  #include <string.h>
>  #include <unistd.h>
>  #include <time.h>
> @@ -13,6 +14,7 @@
>  #include <errno.h>
>  #include <ctype.h>
>  #include <limits.h>
> +#include "../include/linux/initramfs.h"

[Severity: Low]
Since usr/gen_init_cpio.c is compiled as a host userspace program with HOSTCC
and standard libc headers, is the kernel __packed macro defined when
including ../include/linux/initramfs.h?

In include/linux/initramfs.h:

	struct metadata_hdr {
		char c_size[8];     /* total size including c_size field */
		char c_version;     /* header version */
		char c_type;        /* metadata type */
		char c_metadata[];  /* metadata */
	} __packed;

Without a definition for __packed, the host compiler leaves struct
metadata_hdr unpacked and instead parses __packed as a tentative definition
of a global variable named __packed of type struct metadata_hdr.

Should __packed be defined before including initramfs.h (or compiler_attributes.h
included)?

> @@ -37,12 +39,126 @@ static bool do_file_mtime;
[ ... ]
> +static int write_xattrs(const char *path)
> +{
> +	struct metadata_hdr hdr = { .c_version = 1, .c_type = TYPE_XATTR };
> +	char str[sizeof(hdr.c_size) + 1];
> +	char *xattr_list, *list_ptr;
> +	char *xattr_value = NULL;
> +	ssize_t list_len, name_len, value_len, len;
> +	int ret = -EINVAL;
> +
> +	if (metadata_fd < 0)
> +		return 0;
> +
> +	if (path == metadata_path)
> +		return 0;
> +
> +	list_len = llistxattr(path, NULL, 0);

[Severity: Medium]
Can path be NULL when passed to llistxattr() in write_xattrs()?

For non-regular cpio list entries (slink, dir, pipe, sock, and nod), the
source location field is optional and is omitted in standard list files such
as usr/default_cpio_list. When location is omitted, cpio_mkslink_line(),
cpio_mkgeneric_line(), and cpio_mknod_line() pass NULL as location:

	cpio_mkgeneric_line()
	  cpio_mkgeneric(name,
			 nfields == 5 ? cpio_replace_env(location) : NULL,
			 mode, uid, gid)
	    write_xattrs(location)

When gen_init_cpio is invoked with -e xattr, metadata_fd is valid and
write_xattrs() only checks if (metadata_fd < 0) and if (path == metadata_path)
before calling llistxattr(NULL, NULL, 0).

Passing a NULL path to llistxattr() violates the glibc nonnull attribute on
the first parameter (triggering UBSan failures) and can cause a segmentation
fault under LD_PRELOAD environments such as fakeroot or pseudo that
dereference the path string in userspace.

Should write_xattrs() also return 0 if !path?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261030210944.2143778-1-dannyhu@arista.com?part=4

      reply	other threads:[~2026-10-31 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 21:09 [PATCH v5 0/4] initramfs: add support for xattrs in the initial ram disk Danny Hu
2026-10-30 21:09 ` [PATCH v5 1/4] ima: skip algorithm availability check until initramfs unpacking is finished Danny Hu
2026-10-30 21:09 ` [PATCH v5 2/4] initramfs: add file metadata Danny Hu
2026-10-31 21:10   ` sashiko-bot
2026-10-30 21:09 ` [PATCH v5 3/4] initramfs: read metadata from special file METADATA!!! Danny Hu
2026-10-31 21:10   ` sashiko-bot
2026-10-30 21:09 ` [PATCH v5 4/4] gen_init_cpio: add support for file metadata Danny Hu
2026-10-31 21:10   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-192153@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandr.lobakin@intel.com \
    --cc=arnd@arndb.de \
    --cc=brauner@kernel.org \
    --cc=bug-cpio@gnu.org \
    --cc=dannyhu@arista.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=erosca@de.adit-jv.com \
    --cc=hpa@zytor.com \
    --cc=jack@suse.cz \
    --cc=james.w.mcmechan@gmail.com \
    --cc=jim_baxter@mentor.com \
    --cc=julien@arista.com \
    --cc=kamensky@cisco.com \
    --cc=kbharathi@arista.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=niveditas98@gmail.com \
    --cc=nsc@kernel.org \
    --cc=pierre@arista.com \
    --cc=rob@landley.net \
    --cc=roberto.sassu@huawei.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=silviu.vlasceanu@huawei.com \
    --cc=takondra@cisco.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yanaijie@huawei.com \
    --cc=zhangguangzhi3@huawei.com \
    --cc=zhangtianxing3@huawei.com \
    --cc=zhengzengkai@huawei.com \
    --cc=zhoushuiqing2@huawei.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox