diff options
author | Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | 2022-01-27 14:56:56 +0530 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-02-16 09:48:51 +0000 |
commit | 169e03b9b3778fb87af39c64937d5315d4fe434a (patch) | |
tree | cd98fc245baa8d490099f38fe0175d15bd487221 /meta/recipes-core/util-linux/util-linux | |
parent | 239fa60002ae8fcb8dd0a5caff2a96cd1c97de33 (diff) | |
download | poky-169e03b9b3778fb87af39c64937d5315d4fe434a.tar.gz |
util-linux: Fix for CVE-2021-3995 and CVE-2021-3996
Add patches to fix CVE-2021-3995 and CVE-2021-3996
Also, add support include-strutils-cleanup-strto-functions.patch to
solve compilation error where `ul_strtou64` function not found which is
used in CVE-2021-3995.patch
(From OE-Core rev: c8c29e8927474f32343b1f6d47595df95f743cd2)
Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com>
Signed-off-by: Ranjitsinh Rathod <ranjitsinhrathod1991@gmail.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/util-linux/util-linux')
3 files changed, 635 insertions, 0 deletions
diff --git a/meta/recipes-core/util-linux/util-linux/CVE-2021-3995.patch b/meta/recipes-core/util-linux/util-linux/CVE-2021-3995.patch new file mode 100644 index 0000000000..1dcb66ad1d --- /dev/null +++ b/meta/recipes-core/util-linux/util-linux/CVE-2021-3995.patch | |||
@@ -0,0 +1,139 @@ | |||
1 | From f3db9bd609494099f0c1b95231c5dfe383346929 Mon Sep 17 00:00:00 2001 | ||
2 | From: Karel Zak <kzak@redhat.com> | ||
3 | Date: Wed, 24 Nov 2021 13:53:25 +0100 | ||
4 | Subject: [PATCH] libmount: fix UID check for FUSE umount [CVE-2021-3995] | ||
5 | |||
6 | Improper UID check allows an unprivileged user to unmount FUSE | ||
7 | filesystems of users with similar UID. | ||
8 | |||
9 | Signed-off-by: Karel Zak <kzak@redhat.com> | ||
10 | |||
11 | CVE: CVE-2021-3995 | ||
12 | Upstream-Status: Backport [https://github.com/util-linux/util-linux/commit/f3db9bd609494099f0c1b95231c5dfe383346929] | ||
13 | Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | ||
14 | |||
15 | --- | ||
16 | include/strutils.h | 2 +- | ||
17 | libmount/src/context_umount.c | 14 +++--------- | ||
18 | libmount/src/mountP.h | 1 + | ||
19 | libmount/src/optstr.c | 42 +++++++++++++++++++++++++++++++++++ | ||
20 | 4 files changed, 47 insertions(+), 12 deletions(-) | ||
21 | |||
22 | diff --git a/include/strutils.h b/include/strutils.h | ||
23 | index 6e95707ea9..a84d29594d 100644 | ||
24 | --- a/include/strutils.h | ||
25 | +++ b/include/strutils.h | ||
26 | @@ -91,8 +91,8 @@ static inline char *mem2strcpy(char *dest, const void *src, size_t n, size_t nma | ||
27 | if (n + 1 > nmax) | ||
28 | n = nmax - 1; | ||
29 | |||
30 | + memset(dest, '\0', nmax); | ||
31 | memcpy(dest, src, n); | ||
32 | - dest[nmax-1] = '\0'; | ||
33 | return dest; | ||
34 | } | ||
35 | |||
36 | diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c | ||
37 | index 173637a15a..8773c65ffa 100644 | ||
38 | --- a/libmount/src/context_umount.c | ||
39 | +++ b/libmount/src/context_umount.c | ||
40 | @@ -393,10 +393,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) | ||
41 | struct libmnt_ns *ns_old; | ||
42 | const char *type = mnt_fs_get_fstype(cxt->fs); | ||
43 | const char *optstr; | ||
44 | - char *user_id = NULL; | ||
45 | - size_t sz; | ||
46 | - uid_t uid; | ||
47 | - char uidstr[sizeof(stringify_value(ULONG_MAX))]; | ||
48 | + uid_t uid, entry_uid; | ||
49 | |||
50 | *errsv = 0; | ||
51 | |||
52 | @@ -413,11 +410,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) | ||
53 | optstr = mnt_fs_get_fs_options(cxt->fs); | ||
54 | if (!optstr) | ||
55 | return 0; | ||
56 | - | ||
57 | - if (mnt_optstr_get_option(optstr, "user_id", &user_id, &sz) != 0) | ||
58 | - return 0; | ||
59 | - | ||
60 | - if (sz == 0 || user_id == NULL) | ||
61 | + if (mnt_optstr_get_uid(optstr, "user_id", &entry_uid) != 0) | ||
62 | return 0; | ||
63 | |||
64 | /* get current user */ | ||
65 | @@ -434,8 +427,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | - snprintf(uidstr, sizeof(uidstr), "%lu", (unsigned long) uid); | ||
70 | - return strncmp(user_id, uidstr, sz) == 0; | ||
71 | + return uid == entry_uid; | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h | ||
76 | index d43a835418..22442ec55e 100644 | ||
77 | --- a/libmount/src/mountP.h | ||
78 | +++ b/libmount/src/mountP.h | ||
79 | @@ -400,6 +400,7 @@ extern const struct libmnt_optmap *mnt_optmap_get_entry( | ||
80 | const struct libmnt_optmap **mapent); | ||
81 | |||
82 | /* optstr.c */ | ||
83 | +extern int mnt_optstr_get_uid(const char *optstr, const char *name, uid_t *uid); | ||
84 | extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end); | ||
85 | extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next); | ||
86 | extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next); | ||
87 | diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c | ||
88 | index 921b9318e7..16800f571c 100644 | ||
89 | --- a/libmount/src/optstr.c | ||
90 | +++ b/libmount/src/optstr.c | ||
91 | @@ -1090,6 +1090,48 @@ int mnt_optstr_fix_user(char **optstr) | ||
92 | return rc; | ||
93 | } | ||
94 | |||
95 | +/* | ||
96 | + * Converts value from @optstr addressed by @name to uid. | ||
97 | + * | ||
98 | + * Returns: 0 on success, 1 if not found, <0 on error | ||
99 | + */ | ||
100 | +int mnt_optstr_get_uid(const char *optstr, const char *name, uid_t *uid) | ||
101 | +{ | ||
102 | + char *value = NULL; | ||
103 | + size_t valsz = 0; | ||
104 | + char buf[sizeof(stringify_value(UINT64_MAX))]; | ||
105 | + int rc; | ||
106 | + uint64_t num; | ||
107 | + | ||
108 | + assert(optstr); | ||
109 | + assert(name); | ||
110 | + assert(uid); | ||
111 | + | ||
112 | + rc = mnt_optstr_get_option(optstr, name, &value, &valsz); | ||
113 | + if (rc != 0) | ||
114 | + goto fail; | ||
115 | + | ||
116 | + if (valsz > sizeof(buf) - 1) { | ||
117 | + rc = -ERANGE; | ||
118 | + goto fail; | ||
119 | + } | ||
120 | + mem2strcpy(buf, value, valsz, sizeof(buf)); | ||
121 | + | ||
122 | + rc = ul_strtou64(buf, &num, 10); | ||
123 | + if (rc != 0) | ||
124 | + goto fail; | ||
125 | + if (num > ULONG_MAX || (uid_t) num != num) { | ||
126 | + rc = -ERANGE; | ||
127 | + goto fail; | ||
128 | + } | ||
129 | + *uid = (uid_t) num; | ||
130 | + | ||
131 | + return 0; | ||
132 | +fail: | ||
133 | + DBG(UTILS, ul_debug("failed to convert '%s'= to number [rc=%d]", name, rc)); | ||
134 | + return rc; | ||
135 | +} | ||
136 | + | ||
137 | /** | ||
138 | * mnt_match_options: | ||
139 | * @optstr: options string | ||
diff --git a/meta/recipes-core/util-linux/util-linux/CVE-2021-3996.patch b/meta/recipes-core/util-linux/util-linux/CVE-2021-3996.patch new file mode 100644 index 0000000000..1610b5a0fe --- /dev/null +++ b/meta/recipes-core/util-linux/util-linux/CVE-2021-3996.patch | |||
@@ -0,0 +1,226 @@ | |||
1 | From 018a10907fa9885093f6d87401556932c2d8bd2b Mon Sep 17 00:00:00 2001 | ||
2 | From: Karel Zak <kzak@redhat.com> | ||
3 | Date: Tue, 4 Jan 2022 10:54:20 +0100 | ||
4 | Subject: [PATCH] libmount: fix (deleted) suffix issue [CVE-2021-3996] | ||
5 | |||
6 | This issue is related to parsing the /proc/self/mountinfo file allows an | ||
7 | unprivileged user to unmount other user's filesystems that are either | ||
8 | world-writable themselves or mounted in a world-writable directory. | ||
9 | |||
10 | The support for "(deleted)" is no more necessary as the Linux kernel does | ||
11 | not use it in /proc/self/mountinfo and /proc/self/mount files anymore. | ||
12 | |||
13 | Signed-off-by: Karel Zak <kzak@redhat.com> | ||
14 | |||
15 | CVE: CVE-2021-3996 | ||
16 | Upstream-Status: Backport [https://github.com/util-linux/util-linux/commit/018a10907fa9885093f6d87401556932c2d8bd2b] | ||
17 | Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | ||
18 | |||
19 | --- | ||
20 | libmount/src/tab_parse.c | 5 ----- | ||
21 | tests/expected/findmnt/filter-options | 1 - | ||
22 | tests/expected/findmnt/filter-options-nameval-neg | 3 +-- | ||
23 | tests/expected/findmnt/filter-types-neg | 1 - | ||
24 | tests/expected/findmnt/outputs-default | 3 +-- | ||
25 | tests/expected/findmnt/outputs-force-tree | 3 +-- | ||
26 | tests/expected/findmnt/outputs-kernel | 3 +-- | ||
27 | tests/expected/libmount/tabdiff-mount | 1 - | ||
28 | tests/expected/libmount/tabdiff-move | 1 - | ||
29 | tests/expected/libmount/tabdiff-remount | 1 - | ||
30 | tests/expected/libmount/tabdiff-umount | 1 - | ||
31 | tests/expected/libmount/tabfiles-parse-mountinfo | 11 ----------- | ||
32 | tests/expected/libmount/tabfiles-py-parse-mountinfo | 11 ----------- | ||
33 | tests/ts/findmnt/files/mountinfo | 1 - | ||
34 | tests/ts/findmnt/files/mountinfo-nonroot | 1 - | ||
35 | tests/ts/libmount/files/mountinfo | 1 - | ||
36 | 16 files changed, 4 insertions(+), 44 deletions(-) | ||
37 | |||
38 | diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c | ||
39 | index 917779ab6d..4407f9c9c7 100644 | ||
40 | --- a/libmount/src/tab_parse.c | ||
41 | +++ b/libmount/src/tab_parse.c | ||
42 | @@ -225,11 +225,6 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, const char *s) | ||
43 | goto fail; | ||
44 | } | ||
45 | |||
46 | - /* remove "\040(deleted)" suffix */ | ||
47 | - p = (char *) endswith(fs->target, PATH_DELETED_SUFFIX); | ||
48 | - if (p && *p) | ||
49 | - *p = '\0'; | ||
50 | - | ||
51 | s = skip_separator(s); | ||
52 | |||
53 | /* (6) vfs options (fs-independent) */ | ||
54 | diff --git a/tests/expected/findmnt/filter-options b/tests/expected/findmnt/filter-options | ||
55 | index 2606bce76b..97b0ead0ad 100644 | ||
56 | --- a/tests/expected/findmnt/filter-options | ||
57 | +++ b/tests/expected/findmnt/filter-options | ||
58 | @@ -28,5 +28,4 @@ TARGET SOURCE FSTYPE OPTIONS | ||
59 | /home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
60 | /var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
61 | /mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
62 | -/mnt/foo /fooooo bar rw,relatime | ||
63 | rc=0 | ||
64 | diff --git a/tests/expected/findmnt/filter-options-nameval-neg b/tests/expected/findmnt/filter-options-nameval-neg | ||
65 | index 5471d65af1..f0467ef755 100644 | ||
66 | --- a/tests/expected/findmnt/filter-options-nameval-neg | ||
67 | +++ b/tests/expected/findmnt/filter-options-nameval-neg | ||
68 | @@ -29,6 +29,5 @@ TARGET SOURCE FSTYPE OPTIO | ||
69 | |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered | ||
70 | | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
71 | |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
72 | -|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
73 | -`-/mnt/foo /fooooo bar rw,relatime | ||
74 | +`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
75 | rc=0 | ||
76 | diff --git a/tests/expected/findmnt/filter-types-neg b/tests/expected/findmnt/filter-types-neg | ||
77 | index 2606bce76b..97b0ead0ad 100644 | ||
78 | --- a/tests/expected/findmnt/filter-types-neg | ||
79 | +++ b/tests/expected/findmnt/filter-types-neg | ||
80 | @@ -28,5 +28,4 @@ TARGET SOURCE FSTYPE OPTIONS | ||
81 | /home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
82 | /var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
83 | /mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
84 | -/mnt/foo /fooooo bar rw,relatime | ||
85 | rc=0 | ||
86 | diff --git a/tests/expected/findmnt/outputs-default b/tests/expected/findmnt/outputs-default | ||
87 | index 59495797bd..01599355ec 100644 | ||
88 | --- a/tests/expected/findmnt/outputs-default | ||
89 | +++ b/tests/expected/findmnt/outputs-default | ||
90 | @@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO | ||
91 | |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered | ||
92 | | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
93 | |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
94 | -|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
95 | -`-/mnt/foo /fooooo bar rw,relatime | ||
96 | +`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
97 | rc=0 | ||
98 | diff --git a/tests/expected/findmnt/outputs-force-tree b/tests/expected/findmnt/outputs-force-tree | ||
99 | index 59495797bd..01599355ec 100644 | ||
100 | --- a/tests/expected/findmnt/outputs-force-tree | ||
101 | +++ b/tests/expected/findmnt/outputs-force-tree | ||
102 | @@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO | ||
103 | |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered | ||
104 | | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
105 | |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
106 | -|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
107 | -`-/mnt/foo /fooooo bar rw,relatime | ||
108 | +`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
109 | rc=0 | ||
110 | diff --git a/tests/expected/findmnt/outputs-kernel b/tests/expected/findmnt/outputs-kernel | ||
111 | index 59495797bd..01599355ec 100644 | ||
112 | --- a/tests/expected/findmnt/outputs-kernel | ||
113 | +++ b/tests/expected/findmnt/outputs-kernel | ||
114 | @@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO | ||
115 | |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered | ||
116 | | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 | ||
117 | |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime | ||
118 | -|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
119 | -`-/mnt/foo /fooooo bar rw,relatime | ||
120 | +`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
121 | rc=0 | ||
122 | diff --git a/tests/expected/libmount/tabdiff-mount b/tests/expected/libmount/tabdiff-mount | ||
123 | index 420aeacd5e..3c18f8dc4f 100644 | ||
124 | --- a/tests/expected/libmount/tabdiff-mount | ||
125 | +++ b/tests/expected/libmount/tabdiff-mount | ||
126 | @@ -1,3 +1,2 @@ | ||
127 | /dev/mapper/kzak-home on /home/kzak: MOUNTED | ||
128 | -/fooooo on /mnt/foo: MOUNTED | ||
129 | tmpfs on /mnt/test/foo bar: MOUNTED | ||
130 | diff --git a/tests/expected/libmount/tabdiff-move b/tests/expected/libmount/tabdiff-move | ||
131 | index 24f9bc791b..95820d93ef 100644 | ||
132 | --- a/tests/expected/libmount/tabdiff-move | ||
133 | +++ b/tests/expected/libmount/tabdiff-move | ||
134 | @@ -1,3 +1,2 @@ | ||
135 | //foo.home/bar/ on /mnt/music: MOVED to /mnt/music | ||
136 | -/fooooo on /mnt/foo: UMOUNTED | ||
137 | tmpfs on /mnt/test/foo bar: UMOUNTED | ||
138 | diff --git a/tests/expected/libmount/tabdiff-remount b/tests/expected/libmount/tabdiff-remount | ||
139 | index 82ebeab390..876bfd9539 100644 | ||
140 | --- a/tests/expected/libmount/tabdiff-remount | ||
141 | +++ b/tests/expected/libmount/tabdiff-remount | ||
142 | @@ -1,4 +1,3 @@ | ||
143 | /dev/mapper/kzak-home on /home/kzak: REMOUNTED from 'rw,noatime,barrier=1,data=ordered' to 'ro,noatime,barrier=1,data=ordered' | ||
144 | //foo.home/bar/ on /mnt/sounds: REMOUNTED from 'rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344' to 'ro,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344' | ||
145 | -/fooooo on /mnt/foo: UMOUNTED | ||
146 | tmpfs on /mnt/test/foo bar: UMOUNTED | ||
147 | diff --git a/tests/expected/libmount/tabdiff-umount b/tests/expected/libmount/tabdiff-umount | ||
148 | index a3e0fe48a1..c7be725b92 100644 | ||
149 | --- a/tests/expected/libmount/tabdiff-umount | ||
150 | +++ b/tests/expected/libmount/tabdiff-umount | ||
151 | @@ -1,3 +1,2 @@ | ||
152 | /dev/mapper/kzak-home on /home/kzak: UMOUNTED | ||
153 | -/fooooo on /mnt/foo: UMOUNTED | ||
154 | tmpfs on /mnt/test/foo bar: UMOUNTED | ||
155 | diff --git a/tests/expected/libmount/tabfiles-parse-mountinfo b/tests/expected/libmount/tabfiles-parse-mountinfo | ||
156 | index 47eb770061..d5ba5248e4 100644 | ||
157 | --- a/tests/expected/libmount/tabfiles-parse-mountinfo | ||
158 | +++ b/tests/expected/libmount/tabfiles-parse-mountinfo | ||
159 | @@ -351,17 +351,6 @@ id: 47 | ||
160 | parent: 20 | ||
161 | devno: 0:38 | ||
162 | ------ fs: | ||
163 | -source: /fooooo | ||
164 | -target: /mnt/foo | ||
165 | -fstype: bar | ||
166 | -optstr: rw,relatime | ||
167 | -VFS-optstr: rw,relatime | ||
168 | -FS-opstr: rw | ||
169 | -root: / | ||
170 | -id: 48 | ||
171 | -parent: 20 | ||
172 | -devno: 0:39 | ||
173 | ------- fs: | ||
174 | source: tmpfs | ||
175 | target: /mnt/test/foo bar | ||
176 | fstype: tmpfs | ||
177 | diff --git a/tests/expected/libmount/tabfiles-py-parse-mountinfo b/tests/expected/libmount/tabfiles-py-parse-mountinfo | ||
178 | index 47eb770061..d5ba5248e4 100644 | ||
179 | --- a/tests/expected/libmount/tabfiles-py-parse-mountinfo | ||
180 | +++ b/tests/expected/libmount/tabfiles-py-parse-mountinfo | ||
181 | @@ -351,17 +351,6 @@ id: 47 | ||
182 | parent: 20 | ||
183 | devno: 0:38 | ||
184 | ------ fs: | ||
185 | -source: /fooooo | ||
186 | -target: /mnt/foo | ||
187 | -fstype: bar | ||
188 | -optstr: rw,relatime | ||
189 | -VFS-optstr: rw,relatime | ||
190 | -FS-opstr: rw | ||
191 | -root: / | ||
192 | -id: 48 | ||
193 | -parent: 20 | ||
194 | -devno: 0:39 | ||
195 | ------- fs: | ||
196 | source: tmpfs | ||
197 | target: /mnt/test/foo bar | ||
198 | fstype: tmpfs | ||
199 | diff --git a/tests/ts/findmnt/files/mountinfo b/tests/ts/findmnt/files/mountinfo | ||
200 | index 475ea1a337..ff1e664a84 100644 | ||
201 | --- a/tests/ts/findmnt/files/mountinfo | ||
202 | +++ b/tests/ts/findmnt/files/mountinfo | ||
203 | @@ -30,4 +30,3 @@ | ||
204 | 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 | ||
205 | 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw | ||
206 | 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
207 | -48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw | ||
208 | diff --git a/tests/ts/findmnt/files/mountinfo-nonroot b/tests/ts/findmnt/files/mountinfo-nonroot | ||
209 | index e15b467016..87b421d2ef 100644 | ||
210 | --- a/tests/ts/findmnt/files/mountinfo-nonroot | ||
211 | +++ b/tests/ts/findmnt/files/mountinfo-nonroot | ||
212 | @@ -29,4 +29,3 @@ | ||
213 | 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 | ||
214 | 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw | ||
215 | 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
216 | -48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw | ||
217 | diff --git a/tests/ts/libmount/files/mountinfo b/tests/ts/libmount/files/mountinfo | ||
218 | index c063071833..2b01740481 100644 | ||
219 | --- a/tests/ts/libmount/files/mountinfo | ||
220 | +++ b/tests/ts/libmount/files/mountinfo | ||
221 | @@ -30,5 +30,4 @@ | ||
222 | 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 | ||
223 | 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw | ||
224 | 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 | ||
225 | -48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw | ||
226 | 49 20 0:56 / /mnt/test/foo bar rw,relatime shared:323 - tmpfs tmpfs rw | ||
diff --git a/meta/recipes-core/util-linux/util-linux/include-strutils-cleanup-strto-functions.patch b/meta/recipes-core/util-linux/util-linux/include-strutils-cleanup-strto-functions.patch new file mode 100644 index 0000000000..5d5a370821 --- /dev/null +++ b/meta/recipes-core/util-linux/util-linux/include-strutils-cleanup-strto-functions.patch | |||
@@ -0,0 +1,270 @@ | |||
1 | From 84825b161ba5d18da4142893b9789b3fc71284d9 Mon Sep 17 00:00:00 2001 | ||
2 | From: Karel Zak <kzak@redhat.com> | ||
3 | Date: Tue, 22 Jun 2021 14:20:42 +0200 | ||
4 | Subject: [PATCH] include/strutils: cleanup strto..() functions | ||
5 | |||
6 | * add ul_strtos64() and ul_strtou64() | ||
7 | * add simple test | ||
8 | |||
9 | Addresses: https://github.com/karelzak/util-linux/issues/1358 | ||
10 | Signed-off-by: Karel Zak <kzak@redhat.com> | ||
11 | |||
12 | Upstream-Backport: [https://github.com/util-linux/util-linux/commit/84825b161ba5d18da4142893b9789b3fc71284d9] | ||
13 | Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | ||
14 | |||
15 | --- | ||
16 | include/strutils.h | 3 + | ||
17 | lib/strutils.c | 174 ++++++++++++++++++++++++++------------------- | ||
18 | 2 files changed, 105 insertions(+), 72 deletions(-) | ||
19 | |||
20 | diff --git a/include/strutils.h b/include/strutils.h | ||
21 | index e75a2f0e17..389e849905 100644 | ||
22 | --- a/include/strutils.h | ||
23 | +++ b/include/strutils.h | ||
24 | @@ -19,6 +19,9 @@ extern int parse_size(const char *str, uintmax_t *res, int *power); | ||
25 | extern int strtosize(const char *str, uintmax_t *res); | ||
26 | extern uintmax_t strtosize_or_err(const char *str, const char *errmesg); | ||
27 | |||
28 | +extern int ul_strtos64(const char *str, int64_t *num, int base); | ||
29 | +extern int ul_strtou64(const char *str, uint64_t *num, int base); | ||
30 | + | ||
31 | extern int16_t strtos16_or_err(const char *str, const char *errmesg); | ||
32 | extern uint16_t strtou16_or_err(const char *str, const char *errmesg); | ||
33 | extern uint16_t strtox16_or_err(const char *str, const char *errmesg); | ||
34 | diff --git a/lib/strutils.c b/lib/strutils.c | ||
35 | index ee2c835495..d9976dca70 100644 | ||
36 | --- a/lib/strutils.c | ||
37 | +++ b/lib/strutils.c | ||
38 | @@ -319,39 +319,80 @@ char *strndup(const char *s, size_t n) | ||
39 | } | ||
40 | #endif | ||
41 | |||
42 | -static uint32_t _strtou32_or_err(const char *str, const char *errmesg, int base); | ||
43 | -static uint64_t _strtou64_or_err(const char *str, const char *errmesg, int base); | ||
44 | +/* | ||
45 | + * convert strings to numbers; returns <0 on error, and 0 on success | ||
46 | + */ | ||
47 | +int ul_strtos64(const char *str, int64_t *num, int base) | ||
48 | +{ | ||
49 | + char *end = NULL; | ||
50 | |||
51 | -int16_t strtos16_or_err(const char *str, const char *errmesg) | ||
52 | + errno = 0; | ||
53 | + if (str == NULL || *str == '\0') | ||
54 | + return -EINVAL; | ||
55 | + *num = (int64_t) strtoimax(str, &end, base); | ||
56 | + | ||
57 | + if (errno || str == end || (end && *end)) | ||
58 | + return -EINVAL; | ||
59 | + return 0; | ||
60 | +} | ||
61 | + | ||
62 | +int ul_strtou64(const char *str, uint64_t *num, int base) | ||
63 | { | ||
64 | - int32_t num = strtos32_or_err(str, errmesg); | ||
65 | + char *end = NULL; | ||
66 | |||
67 | - if (num < INT16_MIN || num > INT16_MAX) { | ||
68 | - errno = ERANGE; | ||
69 | - err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
70 | - } | ||
71 | - return num; | ||
72 | + errno = 0; | ||
73 | + if (str == NULL || *str == '\0') | ||
74 | + return -EINVAL; | ||
75 | + *num = (uint64_t) strtoumax(str, &end, base); | ||
76 | + | ||
77 | + if (errno || str == end || (end && *end)) | ||
78 | + return -EINVAL; | ||
79 | + return 0; | ||
80 | } | ||
81 | |||
82 | -static uint16_t _strtou16_or_err(const char *str, const char *errmesg, int base) | ||
83 | +/* | ||
84 | + * Covert strings to numbers and print message on error. | ||
85 | + * | ||
86 | + * Note that hex functions (strtox..()) returns unsigned numbers, if you need | ||
87 | + * something else then use ul_strtos64(s, &n, 16). | ||
88 | + */ | ||
89 | +int64_t strtos64_or_err(const char *str, const char *errmesg) | ||
90 | { | ||
91 | - uint32_t num = _strtou32_or_err(str, errmesg, base); | ||
92 | + int64_t num = 0; | ||
93 | |||
94 | - if (num > UINT16_MAX) { | ||
95 | - errno = ERANGE; | ||
96 | - err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
97 | + if (ul_strtos64(str, &num, 10) != 0) { | ||
98 | + if (errno == ERANGE) | ||
99 | + err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
100 | + | ||
101 | + errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
102 | } | ||
103 | return num; | ||
104 | } | ||
105 | |||
106 | -uint16_t strtou16_or_err(const char *str, const char *errmesg) | ||
107 | +uint64_t strtou64_or_err(const char *str, const char *errmesg) | ||
108 | { | ||
109 | - return _strtou16_or_err(str, errmesg, 10); | ||
110 | + uint64_t num = 0; | ||
111 | + | ||
112 | + if (ul_strtou64(str, &num, 10)) { | ||
113 | + if (errno == ERANGE) | ||
114 | + err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
115 | + | ||
116 | + errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
117 | + } | ||
118 | + return num; | ||
119 | } | ||
120 | |||
121 | -uint16_t strtox16_or_err(const char *str, const char *errmesg) | ||
122 | +uint64_t strtox64_or_err(const char *str, const char *errmesg) | ||
123 | { | ||
124 | - return _strtou16_or_err(str, errmesg, 16); | ||
125 | + uint64_t num = 0; | ||
126 | + | ||
127 | + if (ul_strtou64(str, &num, 16)) { | ||
128 | + if (errno == ERANGE) | ||
129 | + err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
130 | + | ||
131 | + errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
132 | + } | ||
133 | + return num; | ||
134 | } | ||
135 | |||
136 | int32_t strtos32_or_err(const char *str, const char *errmesg) | ||
137 | @@ -365,9 +406,9 @@ int32_t strtos32_or_err(const char *str, const char *errmesg) | ||
138 | return num; | ||
139 | } | ||
140 | |||
141 | -static uint32_t _strtou32_or_err(const char *str, const char *errmesg, int base) | ||
142 | +uint32_t strtou32_or_err(const char *str, const char *errmesg) | ||
143 | { | ||
144 | - uint64_t num = _strtou64_or_err(str, errmesg, base); | ||
145 | + uint64_t num = strtou64_or_err(str, errmesg); | ||
146 | |||
147 | if (num > UINT32_MAX) { | ||
148 | errno = ERANGE; | ||
149 | @@ -376,66 +417,48 @@ static uint32_t _strtou32_or_err(const char *str, const char *errmesg, int base) | ||
150 | return num; | ||
151 | } | ||
152 | |||
153 | -uint32_t strtou32_or_err(const char *str, const char *errmesg) | ||
154 | -{ | ||
155 | - return _strtou32_or_err(str, errmesg, 10); | ||
156 | -} | ||
157 | - | ||
158 | uint32_t strtox32_or_err(const char *str, const char *errmesg) | ||
159 | { | ||
160 | - return _strtou32_or_err(str, errmesg, 16); | ||
161 | + uint64_t num = strtox64_or_err(str, errmesg); | ||
162 | + | ||
163 | + if (num > UINT32_MAX) { | ||
164 | + errno = ERANGE; | ||
165 | + err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
166 | + } | ||
167 | + return num; | ||
168 | } | ||
169 | |||
170 | -int64_t strtos64_or_err(const char *str, const char *errmesg) | ||
171 | +int16_t strtos16_or_err(const char *str, const char *errmesg) | ||
172 | { | ||
173 | - int64_t num; | ||
174 | - char *end = NULL; | ||
175 | - | ||
176 | - errno = 0; | ||
177 | - if (str == NULL || *str == '\0') | ||
178 | - goto err; | ||
179 | - num = strtoimax(str, &end, 10); | ||
180 | - | ||
181 | - if (errno || str == end || (end && *end)) | ||
182 | - goto err; | ||
183 | + int64_t num = strtos64_or_err(str, errmesg); | ||
184 | |||
185 | - return num; | ||
186 | -err: | ||
187 | - if (errno == ERANGE) | ||
188 | + if (num < INT16_MIN || num > INT16_MAX) { | ||
189 | + errno = ERANGE; | ||
190 | err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
191 | - | ||
192 | - errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
193 | + } | ||
194 | + return num; | ||
195 | } | ||
196 | |||
197 | -static uint64_t _strtou64_or_err(const char *str, const char *errmesg, int base) | ||
198 | +uint16_t strtou16_or_err(const char *str, const char *errmesg) | ||
199 | { | ||
200 | - uintmax_t num; | ||
201 | - char *end = NULL; | ||
202 | - | ||
203 | - errno = 0; | ||
204 | - if (str == NULL || *str == '\0') | ||
205 | - goto err; | ||
206 | - num = strtoumax(str, &end, base); | ||
207 | - | ||
208 | - if (errno || str == end || (end && *end)) | ||
209 | - goto err; | ||
210 | + uint64_t num = strtou64_or_err(str, errmesg); | ||
211 | |||
212 | - return num; | ||
213 | -err: | ||
214 | - if (errno == ERANGE) | ||
215 | + if (num > UINT16_MAX) { | ||
216 | + errno = ERANGE; | ||
217 | err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
218 | - | ||
219 | - errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
220 | + } | ||
221 | + return num; | ||
222 | } | ||
223 | |||
224 | -uint64_t strtou64_or_err(const char *str, const char *errmesg) | ||
225 | +uint16_t strtox16_or_err(const char *str, const char *errmesg) | ||
226 | { | ||
227 | - return _strtou64_or_err(str, errmesg, 10); | ||
228 | -} | ||
229 | + uint64_t num = strtox64_or_err(str, errmesg); | ||
230 | |||
231 | -uint64_t strtox64_or_err(const char *str, const char *errmesg) | ||
232 | -{ | ||
233 | - return _strtou64_or_err(str, errmesg, 16); | ||
234 | + if (num > UINT16_MAX) { | ||
235 | + errno = ERANGE; | ||
236 | + err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); | ||
237 | + } | ||
238 | + return num; | ||
239 | } | ||
240 | |||
241 | double strtod_or_err(const char *str, const char *errmesg) | ||
242 | @@ -1051,15 +1051,25 @@ static int test_strutils_cmp_paths(int a | ||
243 | |||
244 | int main(int argc, char *argv[]) | ||
245 | { | ||
246 | - if (argc == 3 && strcmp(argv[1], "--size") == 0) | ||
247 | + if (argc == 3 && strcmp(argv[1], "--size") == 0) { | ||
248 | return test_strutils_sizes(argc - 1, argv + 1); | ||
249 | |||
250 | - else if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0) | ||
251 | + } else if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0) { | ||
252 | return test_strutils_cmp_paths(argc - 1, argv + 1); | ||
253 | |||
254 | + } else if (argc == 3 && strcmp(argv[1], "--str2num") == 0) { | ||
255 | + uint64_t n; | ||
256 | + | ||
257 | + if (ul_strtou64(argv[2], &n, 10) == 0) { | ||
258 | + printf("'%s' --> %ju\n", argv[2], (uintmax_t) n); | ||
259 | + return EXIT_SUCCESS; | ||
260 | + } | ||
261 | + } | ||
262 | + | ||
263 | else { | ||
264 | fprintf(stderr, "usage: %1$s --size <number>[suffix]\n" | ||
265 | - " %1$s --cmp-paths <path> <path>\n", | ||
266 | + " %1$s --cmp-paths <path> <path>\n" | ||
267 | + " %1$s --num2num <str>\n", | ||
268 | argv[0]); | ||
269 | exit(EXIT_FAILURE); | ||
270 | } | ||