···11+commit 68564ebb50f8afab5a9527c534417e247cca0b27
22+Author: Filipe Manana <fdmanana@kernel.org>
33+Date: Thu Aug 17 10:20:13 2023 +0100
44+55+ libmount: Fix regression when mounting with atime
66+77+ A regression was introduced in v2.39 that causes mounting with the atime
88+ option to fail:
99+1010+ $ mkfs.ext4 -F /dev/sdi
1111+ $ mount -o atime /dev/sdi /mnt/sdi
1212+ mount: /mnt/sdi: not mount point or bad option.
1313+ dmesg(1) may have more information after failed mount system call.
1414+1515+ The failure comes from the mount_setattr(2) call returning -EINVAL. This
1616+ is because we pass an invalid value for the attr_clr argument. From a
1717+ strace capture we have:
1818+1919+ mount_setattr(4, "", AT_EMPTY_PATH, {attr_set=0, attr_clr=MOUNT_ATTR_NOATIME, propagation=0 /* MS_??? */, userns_fd=0}, 32) = -1 EINVAL (Invalid argument)
2020+2121+ We can't pass MOUNT_ATTR_NOATIME to mount_setattr(2) through the attr_clr
2222+ argument because all atime options are exclusive, so in order to set atime
2323+ one has to pass MOUNT_ATTR__ATIME to attr_clr and leave attr_set as
2424+ MOUNT_ATTR_RELATIME (which is defined as a value of 0).
2525+2626+ This can be read from the man page for mount_setattr(2) and also from the
2727+ kernel source:
2828+2929+ $ cat fs/namespace.c
3030+ static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
3131+ struct mount_kattr *kattr, unsigned int flags)
3232+ {
3333+ (...)
3434+ /*
3535+ * Since the MOUNT_ATTR_<atime> values are an enum, not a bitmap,
3636+ * users wanting to transition to a different atime setting cannot
3737+ * simply specify the atime setting in @attr_set, but must also
3838+ * specify MOUNT_ATTR__ATIME in the @attr_clr field.
3939+ * So ensure that MOUNT_ATTR__ATIME can't be partially set in
4040+ * @attr_clr and that @attr_set can't have any atime bits set if
4141+ * MOUNT_ATTR__ATIME isn't set in @attr_clr.
4242+ */
4343+ if (attr->attr_clr & MOUNT_ATTR__ATIME) {
4444+ if ((attr->attr_clr & MOUNT_ATTR__ATIME) != MOUNT_ATTR__ATIME)
4545+ return -EINVAL;
4646+4747+ /*
4848+ * Clear all previous time settings as they are mutually
4949+ * exclusive.
5050+ */
5151+ kattr->attr_clr |= MNT_RELATIME | MNT_NOATIME;
5252+ switch (attr->attr_set & MOUNT_ATTR__ATIME) {
5353+ case MOUNT_ATTR_RELATIME:
5454+ kattr->attr_set |= MNT_RELATIME;
5555+ break;
5656+ case MOUNT_ATTR_NOATIME:
5757+ kattr->attr_set |= MNT_NOATIME;
5858+ break;
5959+ case MOUNT_ATTR_STRICTATIME:
6060+ break;
6161+ default:
6262+ return -EINVAL;
6363+ }
6464+ (...)
6565+6666+ So fix this by setting attr_clr MOUNT_ATTR__ATIME if we want to clear any
6767+ atime related option.
6868+6969+ Signed-off-by: Filipe Manana <fdmanana@kernel.org>
7070+7171+diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c
7272+index 1e962ec6d..0702adae7 100644
7373+--- a/libmount/src/optlist.c
7474++++ b/libmount/src/optlist.c
7575+@@ -875,7 +875,18 @@ int mnt_optlist_get_attrs(struct libmnt_optlist *ls, uint64_t *set, uint64_t *cl
7676+7777+ if (opt->ent->mask & MNT_INVERT) {
7878+ DBG(OPTLIST, ul_debugobj(ls, " clr: %s", opt->ent->name));
7979+- *clr |= x;
8080++ /*
8181++ * All atime settings are mutually exclusive so *clr must
8282++ * have MOUNT_ATTR__ATIME set.
8383++ *
8484++ * See the function fs/namespace.c:build_mount_kattr()
8585++ * in the linux kernel source.
8686++ */
8787++ if (x == MOUNT_ATTR_RELATIME || x == MOUNT_ATTR_NOATIME ||
8888++ x == MOUNT_ATTR_STRICTATIME)
8989++ *clr |= MOUNT_ATTR__ATIME;
9090++ else
9191++ *clr |= x;
9292+ } else {
9393+ DBG(OPTLIST, ul_debugobj(ls, " set: %s", opt->ent->name));
9494+ *set |= x;
9595+diff --git a/tests/expected/libmount/context-mount-flags b/tests/expected/libmount/context-mount-flags
9696+index 960641863..eb71323dd 100644
9797+--- a/tests/expected/libmount/context-mount-flags
9898++++ b/tests/expected/libmount/context-mount-flags
9999+@@ -3,3 +3,6 @@ ro,nosuid,noexec
100100+ successfully mounted
101101+ rw,nosuid,noexec
102102+ successfully umounted
103103++successfully mounted
104104++rw,relatime
105105++successfully umounted
106106+diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context
107107+index f5b47185e..a5d2e81a3 100755
108108+--- a/tests/ts/libmount/context
109109++++ b/tests/ts/libmount/context
110110+@@ -116,8 +116,15 @@ $TS_CMD_FINDMNT --kernel --mountpoint $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPU
111111+112112+ ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
113113+ is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
114114+-ts_finalize_subtest
115115+116116++# Test that the atime option works after the migration to use the new kernel mount APIs.
117117++ts_run $TESTPROG --mount -o atime $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
118118++$TS_CMD_FINDMNT --kernel --mountpoint $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>> $TS_ERRLOG
119119++is_mounted $DEVICE || echo "$DEVICE not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
120120++ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
121121++is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
122122++
123123++ts_finalize_subtest
124124+125125+ ts_init_subtest "mount-loopdev"
126126+ mkdir -p $MOUNTPOINT &> /dev/null
127127+128128+commit 1ec71634aa4ef5ddca23d65c8a296f3614231e8a
129129+Author: Colin Gillespie <colin@cgillespie.xyz>
130130+Date: Wed Aug 9 18:28:07 2023 +1000
131131+132132+ libblkid: (bcachefs) fix not detecting large superblocks
133133+134134+ Probing does not detect bcachefs filesystems with a superblock larger
135135+ than 4KiB. Bcachefs superblocks grow in size and can become much larger
136136+ than this.
137137+138138+ Increase the superblock maximum size limit to 1MiB.
139139+140140+ Validate the superblock isn't larger than the maximum size defined in
141141+ the superblocks layout section.
142142+143143+ (cherry picked from commit 48d573797797650d96456979797c0155d58f61cb)
144144+145145+diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c
146146+index 40e702d75..236877042 100644
147147+--- a/libblkid/src/superblocks/bcache.c
148148++++ b/libblkid/src/superblocks/bcache.c
149149+@@ -102,6 +102,15 @@ union bcachefs_sb_csum {
150150+ uint8_t raw[16];
151151+ } __attribute__((packed));
152152+153153++struct bcachefs_sb_layout {
154154++ uint8_t magic[16];
155155++ uint8_t layout_type;
156156++ uint8_t sb_max_size_bits;
157157++ uint8_t nr_superblocks;
158158++ uint8_t pad[5];
159159++ uint64_t sb_offset[61];
160160++} __attribute__((packed));
161161++
162162+ struct bcachefs_super_block {
163163+ union bcachefs_sb_csum csum;
164164+ uint16_t version;
165165+@@ -123,7 +132,7 @@ struct bcachefs_super_block {
166166+ uint64_t flags[8];
167167+ uint64_t features[2];
168168+ uint64_t compat[2];
169169+- uint8_t layout[512];
170170++ struct bcachefs_sb_layout layout;
171171+ struct bcachefs_sb_field _start[];
172172+ } __attribute__((packed));
173173+174174+@@ -143,7 +152,7 @@ struct bcachefs_super_block {
175175+ /* granularity of offset and length fields within superblock */
176176+ #define BCACHEFS_SECTOR_SIZE 512
177177+ /* maximum superblock size */
178178+-#define BCACHEFS_SB_MAX_SIZE 4096
179179++#define BCACHEFS_SB_MAX_SIZE 0x100000
180180+ /* fields offset within super block */
181181+ #define BCACHEFS_SB_FIELDS_OFF offsetof(struct bcachefs_super_block, _start)
182182+ /* tag value for members field */
183183+@@ -302,6 +311,9 @@ static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag)
184184+ return BLKID_PROBE_NONE;
185185+186186+ sb_size = BCACHEFS_SB_FIELDS_OFF + BYTES(bcs);
187187++ if (sb_size > BCACHEFS_SECTOR_SIZE << bcs->layout.sb_max_size_bits)
188188++ return BLKID_PROBE_NONE;
189189++
190190+ if (sb_size > BCACHEFS_SB_MAX_SIZE)
191191+ return BLKID_PROBE_NONE;
192192+193193+194194+commit acbf17ae8f8ee0f941fe98ed12f115f2b349bba8
195195+Author: Karel Zak <kzak@redhat.com>
196196+Date: Wed Aug 23 11:53:45 2023 +0200
197197+198198+ libblkid: (bcachefs) fix compiler warning [-Werror=sign-compare]
199199+200200+ Addresses: https://github.com/util-linux/util-linux/pull/2427
201201+ Signed-off-by: Karel Zak <kzak@redhat.com>
202202+ (cherry picked from commit 17873d38fc97913c0a31d4bd08cfbfe45c4de5be)
203203+204204+diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c
205205+index 236877042..6ab3fe9d4 100644
206206+--- a/libblkid/src/superblocks/bcache.c
207207++++ b/libblkid/src/superblocks/bcache.c
208208+@@ -311,7 +311,7 @@ static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag)
209209+ return BLKID_PROBE_NONE;
210210+211211+ sb_size = BCACHEFS_SB_FIELDS_OFF + BYTES(bcs);
212212+- if (sb_size > BCACHEFS_SECTOR_SIZE << bcs->layout.sb_max_size_bits)
213213++ if (sb_size > ((uint64_t) BCACHEFS_SECTOR_SIZE << bcs->layout.sb_max_size_bits))
214214+ return BLKID_PROBE_NONE;
215215+216216+ if (sb_size > BCACHEFS_SB_MAX_SIZE)
217217+218218+commit 6b9fda87c4e5d0c6f945d7565197f157b9fa3d5f
219219+Author: Thomas Weißschuh <thomas@t-8ch.de>
220220+Date: Wed Aug 23 11:58:33 2023 +0200
221221+222222+ libblkid: (bcachefs) fix size validation
223223+224224+ Avoid signed shift out-of-bounds.
225225+226226+ Also mark the constants explitly as unsigned instead of casting.
227227+228228+ Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
229229+ (cherry picked from commit befe455f59de8c7bc66b85ed52aae8cbc95325fa)
230230+231231+diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c
232232+index 6ab3fe9d4..28ac4b52b 100644
233233+--- a/libblkid/src/superblocks/bcache.c
234234++++ b/libblkid/src/superblocks/bcache.c
235235+@@ -142,17 +142,19 @@ struct bcachefs_super_block {
236236+ /* magic string len */
237237+ #define BCACHE_SB_MAGIC_LEN (sizeof(BCACHE_SB_MAGIC) - 1)
238238+ /* super block offset */
239239+-#define BCACHE_SB_OFF 0x1000
240240++#define BCACHE_SB_OFF 0x1000U
241241+ /* supper block offset in kB */
242242+ #define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10)
243243+ /* magic string offset within super block */
244244+ #define BCACHE_SB_MAGIC_OFF offsetof(struct bcache_super_block, magic)
245245+ /* start of checksummed data within superblock */
246246+-#define BCACHE_SB_CSUMMED_START 8
247247++#define BCACHE_SB_CSUMMED_START 8U
248248+ /* granularity of offset and length fields within superblock */
249249+-#define BCACHEFS_SECTOR_SIZE 512
250250++#define BCACHEFS_SECTOR_SIZE 512U
251251++/* maximum superblock size shift */
252252++#define BCACHEFS_SB_MAX_SIZE_SHIFT 0x10U
253253+ /* maximum superblock size */
254254+-#define BCACHEFS_SB_MAX_SIZE 0x100000
255255++#define BCACHEFS_SB_MAX_SIZE (1U << BCACHEFS_SB_MAX_SIZE_SHIFT)
256256+ /* fields offset within super block */
257257+ #define BCACHEFS_SB_FIELDS_OFF offsetof(struct bcachefs_super_block, _start)
258258+ /* tag value for members field */
259259+@@ -311,12 +313,16 @@ static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag)
260260+ return BLKID_PROBE_NONE;
261261+262262+ sb_size = BCACHEFS_SB_FIELDS_OFF + BYTES(bcs);
263263+- if (sb_size > ((uint64_t) BCACHEFS_SECTOR_SIZE << bcs->layout.sb_max_size_bits))
264264+- return BLKID_PROBE_NONE;
265265+266266+ if (sb_size > BCACHEFS_SB_MAX_SIZE)
267267+ return BLKID_PROBE_NONE;
268268+269269++ if (bcs->layout.sb_max_size_bits > BCACHEFS_SB_MAX_SIZE_SHIFT)
270270++ return BLKID_PROBE_NONE;
271271++
272272++ if (sb_size > (BCACHEFS_SECTOR_SIZE << bcs->layout.sb_max_size_bits))
273273++ return BLKID_PROBE_NONE;
274274++
275275+ sb = blkid_probe_get_sb_buffer(pr, mag, sb_size);
276276+ if (!sb)
277277+ return BLKID_PROBE_NONE;
+1
pkgs/os-specific/linux/util-linux/default.nix
···29293030 patches = [
3131 ./rtcwake-search-PATH-for-shutdown.patch
3232+ ./bcachefs-patch-set.patch
3233 ];
33343435 # We separate some of the utilities into their own outputs. This