!201 [sync] PR-200: sync patches from upstream

From: @openeuler-sync-bot 
Reviewed-by: @openeuler-basic 
Signed-off-by: @openeuler-basic
This commit is contained in:
openeuler-ci-bot 2024-02-19 12:31:33 +00:00 committed by Gitee
commit fc278503e9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 296 additions and 1 deletions

View File

@ -0,0 +1,35 @@
From 68459714838c8c0c2d34b6d658638f5d59298bc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Sun, 1 Oct 2023 13:57:12 +0200
Subject: [PATCH] include/c.h: add helpers for unaligned structure access
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
include/c.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/c.h b/include/c.h
index 752f568c5..224a8e54f 100644
--- a/include/c.h
+++ b/include/c.h
@@ -213,6 +213,14 @@
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
+#define read_unaligned_member(p, m) __extension__ ({ \
+ size_t offset = offsetof(__typeof__(* p), m); \
+ __typeof__(p->m) v; \
+ memcpy(&v, ((unsigned char *)p) + offset, sizeof(v)); \
+ v; })
+
+#define member_ptr(p, m) (((unsigned char *)p) + offsetof(__typeof__(*p), m))
+
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
# ifdef HAVE___PROGNAME
extern char *__progname;
--
2.33.0

View File

@ -0,0 +1,46 @@
From 025b11465d086c55948eff484f40c993f2184990 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Fri, 12 Jan 2024 08:47:50 +0100
Subject: [PATCH] libblkid: avoid aligning out of probing area
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When reading from the end of the device the IO size alignment could
enlarge the read buffer outside of the probing area.
This would then trigger a read failure.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
libblkid/src/probe.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index fee5b55..0e716b5 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -648,13 +648,18 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len)
unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
{
struct blkid_bufinfo *bf = NULL;
- uint64_t real_off, bias;
+ uint64_t real_off, bias, len_align;
bias = off % pr->io_size;
off -= bias;
len += bias;
- if (len % pr->io_size)
- len += pr->io_size - (len % pr->io_size);
+
+ if (len % pr->io_size) {
+ len_align = pr->io_size - (len % pr->io_size);
+
+ if (pr->off + off + len + len_align <= pr->size)
+ len += len_align;
+ }
real_off = pr->off + off;
--
2.33.0

View File

@ -0,0 +1,81 @@
From 4ee2db2a221f6404f9fe9470da7c384a25cceea3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Fri, 12 Jan 2024 08:50:14 +0100
Subject: [PATCH] libblkid: (drbd) validate zero padding
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This should reduce false-positives.
See #2701.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
libblkid/src/superblocks/drbd.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c
index f360186..1723229 100644
--- a/libblkid/src/superblocks/drbd.c
+++ b/libblkid/src/superblocks/drbd.c
@@ -70,9 +70,8 @@ struct md_on_disk_08 {
uint32_t bm_bytes_per_bit;
uint32_t reserved_u32[4];
- /* Unnecessary for libblkid **
- * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
- */
+ unsigned char padding_start[0];
+ unsigned char padding_end[0] __attribute__((aligned(4096)));
};
/*
@@ -118,11 +117,19 @@ struct meta_data_on_disk_9 {
struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX];
uint64_t history_uuids[HISTORY_UUIDS];
- /* Unnecessary for libblkid **
- * char padding[0] __attribute__((aligned(4096)));
- */
+ unsigned char padding_start[0];
+ unsigned char padding_end[0] __attribute__((aligned(4096)));
} __attribute__((packed));
+static int is_zero_padded(const unsigned char *padding_start,
+ const unsigned char *padding_end)
+{
+ for (; padding_start < padding_end; padding_start++) {
+ if (*padding_start != 0)
+ return 0;
+ }
+ return 1;
+}
static int probe_drbd_84(blkid_probe pr)
{
@@ -146,6 +153,10 @@ static int probe_drbd_84(blkid_probe pr)
be32_to_cpu(md->magic) != DRBD_MD_MAGIC_84_UNCLEAN)
return 1;
+ if (!is_zero_padded(member_ptr(md, padding_start),
+ member_ptr(md, padding_end)))
+ return 1;
+
/*
* DRBD does not have "real" uuids; the following resembles DRBD's
* notion of uuids (64 bit, see struct above)
@@ -190,6 +201,10 @@ static int probe_drbd_90(blkid_probe pr)
if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_09)
return 1;
+ if (!is_zero_padded(member_ptr(md, padding_start),
+ member_ptr(md, padding_end)))
+ return 1;
+
/*
* DRBD does not have "real" uuids; the following resembles DRBD's
* notion of uuids (64 bit, see struct above)
--
2.33.0

View File

@ -0,0 +1,119 @@
From 8a534253bc52f453db21af02299efacd12f40fda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Sat, 30 Sep 2023 23:59:44 +0200
Subject: [PATCH] libblkid: (probe) read data in chunks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
libblkid/src/blkidP.h | 1 +
libblkid/src/probe.c | 39 ++++++++++++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index 5fbab82..af949c0 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -201,6 +201,7 @@ struct blkid_struct_probe
int fd; /* device file descriptor */
uint64_t off; /* begin of data on the device */
uint64_t size; /* end of data on the device */
+ uint64_t io_size; /* optimal size of IO */
dev_t devno; /* device number (st.st_rdev) */
dev_t disk_devno; /* devno of the whole-disk or 0 */
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 2e36274..fee5b55 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -173,6 +173,7 @@ blkid_probe blkid_clone_probe(blkid_probe parent)
pr->fd = parent->fd;
pr->off = parent->off;
pr->size = parent->size;
+ pr->io_size = parent->io_size;
pr->devno = parent->devno;
pr->disk_devno = parent->disk_devno;
pr->blkssz = parent->blkssz;
@@ -647,13 +648,21 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len)
unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
{
struct blkid_bufinfo *bf = NULL;
- uint64_t real_off = pr->off + off;
+ uint64_t real_off, bias;
+
+ bias = off % pr->io_size;
+ off -= bias;
+ len += bias;
+ if (len % pr->io_size)
+ len += pr->io_size - (len % pr->io_size);
+
+ real_off = pr->off + off;
/*
DBG(BUFFER, ul_debug("\t>>>> off=%ju, real-off=%ju (probe <%ju..%ju>, len=%ju",
off, real_off, pr->off, pr->off + pr->size, len));
*/
- if (pr->size == 0) {
+ if (pr->size == 0 || pr->io_size == 0) {
errno = EINVAL;
return NULL;
}
@@ -700,7 +709,7 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len
assert(bf->off + bf->len >= real_off + len);
errno = 0;
- return real_off ? bf->data + (real_off - bf->off) : bf->data;
+ return real_off ? bf->data + (real_off - bf->off + bias) : bf->data + bias;
}
/**
@@ -861,6 +870,22 @@ failed:
#endif
+static uint64_t blkid_get_io_size(int fd)
+{
+ static const int ioctls[] = { BLKIOOPT, BLKIOMIN, BLKBSZGET };
+ unsigned int s;
+ size_t i;
+ int r;
+
+ for (i = 0; i < ARRAY_SIZE(ioctls); i++) {
+ r = ioctl(fd, ioctls[i], &s);
+ if (r == 0 && is_power_of_2(s) && s >= DEFAULT_SECTOR_SIZE)
+ return min(s, 1U << 16);
+ }
+
+ return DEFAULT_SECTOR_SIZE;
+}
+
/**
* blkid_probe_set_device:
* @pr: probe
@@ -906,6 +931,7 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
pr->fd = fd;
pr->off = (uint64_t) off;
pr->size = 0;
+ pr->io_size = DEFAULT_SECTOR_SIZE;
pr->devno = 0;
pr->disk_devno = 0;
pr->mode = 0;
@@ -1012,8 +1038,11 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
#endif
free(dm_uuid);
- DBG(LOWPROBE, ul_debug("ready for low-probing, offset=%"PRIu64", size=%"PRIu64"",
- pr->off, pr->size));
+ if (S_ISBLK(sb.st_mode) && !blkid_probe_is_tiny(pr))
+ pr->io_size = blkid_get_io_size(fd);
+
+ DBG(LOWPROBE, ul_debug("ready for low-probing, offset=%"PRIu64", size=%"PRIu64", iosize=%"PRIu64,
+ pr->off, pr->size, pr->io_size));
DBG(LOWPROBE, ul_debug("whole-disk: %s, regfile: %s",
blkid_probe_is_wholedisk(pr) ?"YES" : "NO",
S_ISREG(pr->mode) ? "YES" : "NO"));
--
2.33.0

View File

@ -3,7 +3,7 @@
Name: util-linux Name: util-linux
Version: 2.37.2 Version: 2.37.2
Release: 24 Release: 25
Summary: A random collection of Linux utilities Summary: A random collection of Linux utilities
License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain
URL: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git URL: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
@ -131,6 +131,10 @@ Patch6109: backport-libsmartcols-flush-correct-stream.patch
Patch6110: backport-libsmartcols-only-recognize-closed-object-as-final-e.patch Patch6110: backport-libsmartcols-only-recognize-closed-object-as-final-e.patch
Patch6111: backport-cal-avoid-out-of-bound-write.patch Patch6111: backport-cal-avoid-out-of-bound-write.patch
Patch6112: backport-libfdisk-sun-properly-initialize-partition-data.patch Patch6112: backport-libfdisk-sun-properly-initialize-partition-data.patch
Patch6113: backport-include-c.h-add-helpers-for-unaligned-structure-acce.patch
Patch6114: backport-libblkid-probe-read-data-in-chunks.patch
Patch6115: backport-libblkid-avoid-aligning-out-of-probing-area.patch
Patch6116: backport-libblkid-drbd-validate-zero-padding.patch
Patch9000: Add-check-to-resolve-uname26-version-test-failed.patch Patch9000: Add-check-to-resolve-uname26-version-test-failed.patch
Patch9001: SKIPPED-no-root-permissions-test.patch Patch9001: SKIPPED-no-root-permissions-test.patch
@ -502,6 +506,16 @@ fi
%{_mandir}/man8/{swapoff.8*,swapon.8*,switch_root.8*,umount.8*,wdctl.8.gz,wipefs.8*,zramctl.8*} %{_mandir}/man8/{swapoff.8*,swapon.8*,switch_root.8*,umount.8*,wdctl.8.gz,wipefs.8*,zramctl.8*}
%changelog %changelog
* Mon Feb 19 2024 zhangyao <zhangyao108@huawei.com> - 2.37.2-25
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:solve the issue of ext4 is incorrectly probed as drbd
[add]backport-include-c.h-add-helpers-for-unaligned-structure-acce.patch
backport-libblkid-probe-read-data-in-chunks.patch
backport-libblkid-avoid-aligning-out-of-probing-area.patch
backport-libblkid-drbd-validate-zero-padding.patch
* Tue Jan 16 2024 zhangyao <zhangyao108@huawei.com> - 2.37.2-24 * Tue Jan 16 2024 zhangyao <zhangyao108@huawei.com> - 2.37.2-24
- Type:bugfix - Type:bugfix
- CVE:NA - CVE:NA