Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP4:Update
xfsprogs.34579
xfsprogs-mkfs-prevent-corruption-of-passed-in-s...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File xfsprogs-mkfs-prevent-corruption-of-passed-in-suboption-strin.patch of Package xfsprogs.34579
From 99c7877759c0d0e7cd1b386c717e25dbc6f5ce61 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" <djwong@kernel.org> Date: Fri, 25 Feb 2022 17:42:16 -0500 Subject: [PATCH] mkfs: prevent corruption of passed-in suboption string values Git-commit: 99c7877759c0d0e7cd1b386c717e25dbc6f5ce61 Patch-mainline: v5.15.0-rc1 References: bsc#1205377 Eric and I were trying to play with mkfs.configuration files, when I spotted this (with the libini package from Ubuntu 20.04): # cat << EOF > /tmp/r [data] su=2097152 sw=1 EOF # mkfs.xfs -f -c options=/tmp/r /dev/sda Parameters parsed from config file /tmp/r successfully -d su option requires a value It turns out that libini's parser uses stack variables(!) to store the value of a key=value pair that it parses, and passes this stack array to the parse_cfgopt function. If the particular option calls getstr(), then we save the value of that pointer (not its contents) to the cli_params. Being a stack array, the contents will be overwritten by other function calls, which means that our value of '2097152' has been destroyed by the time we actually call getnum when we're validating the new fs config. We never noticed this until now because the only other caller was getsubopt on the argv array, which gets chopped up but left intact in memory. The solution is to make a private copy of those strings if we ever save them for later. For now we'll be lazy and let the memory leak, since mkfs is not a long-running process. Fixes: 33c62516 ("mkfs: add initial ini format config file parsing support") Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Eric Sandeen <sandeen@sandeen.net> Acked-by: Anthony Iliopoulos <ailiop@suse.com> --- mkfs/xfs_mkfs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) Index: xfsprogs-5.13.0/mkfs/xfs_mkfs.c =================================================================== --- xfsprogs-5.13.0.orig/mkfs/xfs_mkfs.c +++ xfsprogs-5.13.0/mkfs/xfs_mkfs.c @@ -1449,12 +1449,21 @@ getstr( struct opt_params *opts, int index) { + char *ret; + check_opt(opts, index, true); /* empty strings for string options are not valid */ if (!str || *str == '\0') reqval(opts->name, opts->subopts, index); - return (char *)str; + + ret = strdup(str); + if (!ret) { + fprintf(stderr, _("Out of memory while saving suboptions.\n")); + exit(1); + } + + return ret; } static int
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor