!45 fix segmentation fault --offset and output wrong result with --verify
From: @paultohmas Reviewed-by: @liqingqing_1229 Signed-off-by: @liqingqing_1229
This commit is contained in:
commit
c49a84ea36
47
0001-shm.c-Fix-segmentation-fault-when-using-offset.patch
Normal file
47
0001-shm.c-Fix-segmentation-fault-when-using-offset.patch
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
From 66a598db1168a44b0af09aa002eb559d53258205 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Tohmas <relpeace@yeah.net>
|
||||||
|
Date: Thu, 7 Dec 2023 10:35:36 +0800
|
||||||
|
Subject: [PATCH] shm.c: Fix segmentation fault when using offset
|
||||||
|
|
||||||
|
The following command can trigger the bug
|
||||||
|
numactl --offset 4096 --length 65536 --file xxx -p0 --touch
|
||||||
|
|
||||||
|
When we create a shm file, we just consider shmlen, but not consider shmoffset,
|
||||||
|
resulting in the mapped memory is no within the scope of the new shm file.
|
||||||
|
---
|
||||||
|
shm.c | 12 ++++++++----
|
||||||
|
1 file changed, 8 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/shm.c b/shm.c
|
||||||
|
index fb592ed..d5c9828 100644
|
||||||
|
--- a/shm.c
|
||||||
|
+++ b/shm.c
|
||||||
|
@@ -107,8 +107,8 @@ void attach_sysvshm(char *name, char *opt)
|
||||||
|
"need a --length to create a sysv shared memory segment");
|
||||||
|
fprintf(stderr,
|
||||||
|
"numactl: Creating shared memory segment %s id %ld mode %04o length %.fMB\n",
|
||||||
|
- name, shmid, shmmode, ((double)shmlen) / (1024*1024) );
|
||||||
|
- shmfd = shmget(key, shmlen, IPC_CREAT|shmmode|shmflags);
|
||||||
|
+ name, shmid, shmmode, ((double)(shmlen + shmoffset)) / (1024*1024) );
|
||||||
|
+ shmfd = shmget(key, shmlen + shmoffset, IPC_CREAT|shmmode|shmflags);
|
||||||
|
if (shmfd < 0)
|
||||||
|
nerror("cannot create shared memory segment");
|
||||||
|
}
|
||||||
|
@@ -145,8 +145,12 @@ void attach_shared(char *name, char *opt)
|
||||||
|
}
|
||||||
|
if (fstat64(shmfd, &st) < 0)
|
||||||
|
err("shm stat");
|
||||||
|
- if (shmlen > st.st_size) {
|
||||||
|
- if (ftruncate64(shmfd, shmlen) < 0) {
|
||||||
|
+ /* the file size must be larger than mmap shmlen + shmoffset, otherwise SIGBUS
|
||||||
|
+ * will be caused when we access memory, because mmaped memory is no longer in
|
||||||
|
+ * the range of the file laster.
|
||||||
|
+ */
|
||||||
|
+ if ((shmlen + shmoffset) > st.st_size) {
|
||||||
|
+ if (ftruncate64(shmfd, shmlen + shmoffset) < 0) {
|
||||||
|
/* XXX: we could do it by hand, but it would it
|
||||||
|
would be impossible to apply policy then.
|
||||||
|
need to fix that in the kernel. */
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
||||||
28
0002-shm.c-fix-verify_shm-memcmp-nodes.patch
Normal file
28
0002-shm.c-fix-verify_shm-memcmp-nodes.patch
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
From 24d434c209cb337ea4e32c44c100f1d2e69df74e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Tohmas <relpeace@yeah.net>
|
||||||
|
Date: Thu, 7 Dec 2023 10:38:52 +0800
|
||||||
|
Subject: [PATCH] shm.c: fix verify_shm memcmp nodes
|
||||||
|
|
||||||
|
When nodemask_sz is large 64 (CONFIG_NODES_SHIFT > 6), verify_shm
|
||||||
|
will output wrong result "mismatched node mask". that's not what we
|
||||||
|
expected, we expected compare nodes->maskp.
|
||||||
|
---
|
||||||
|
shm.c | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/shm.c b/shm.c
|
||||||
|
index d5c9828..15f4892 100644
|
||||||
|
--- a/shm.c
|
||||||
|
+++ b/shm.c
|
||||||
|
@@ -292,7 +292,7 @@ void verify_shm(int policy, struct bitmask *nodes)
|
||||||
|
policy_name(pol2), policy_name(policy));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
- if (memcmp(nodes2, nodes, numa_bitmask_nbytes(nodes))) {
|
||||||
|
+ if (memcmp(nodes2->maskp, nodes->maskp, numa_bitmask_nbytes(nodes))) {
|
||||||
|
vwarn(p, "mismatched node mask\n");
|
||||||
|
printmask("expected", nodes);
|
||||||
|
printmask("real", nodes2);
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
||||||
11
numactl.spec
11
numactl.spec
@ -1,14 +1,16 @@
|
|||||||
Name: numactl
|
Name: numactl
|
||||||
Version: 2.0.13
|
Version: 2.0.13
|
||||||
Release: 5
|
Release: 6
|
||||||
Summary: Library for tuning for Non Uniform Memory Access machines
|
Summary: Library for tuning for Non Uniform Memory Access machines
|
||||||
License: GPLv2
|
License: GPLv2
|
||||||
URL: https://github.com/numactl/numactl
|
URL: https://github.com/numactl/numactl
|
||||||
Source0: https://github.com/numactl/numactl/releases/download/v%{version}/numactl-%{version}.tar.gz
|
Source0: https://github.com/numactl/numactl/releases/download/v%{version}/numactl-%{version}.tar.gz
|
||||||
BuildRequires: libtool automake autoconf git
|
BuildRequires: libtool automake autoconf git
|
||||||
|
|
||||||
Patch0001: Fix-crashes-when-using-the-touch-option.patch
|
Patch0001: Fix-crashes-when-using-the-touch-option.patch
|
||||||
Patch0002: fix-use-after-free.patch
|
Patch0002: fix-use-after-free.patch
|
||||||
|
Patch0003: 0001-shm.c-Fix-segmentation-fault-when-using-offset.patch
|
||||||
|
Patch0004: 0002-shm.c-fix-verify_shm-memcmp-nodes.patch
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Simple NUMA policy support. It consists of a numactl program to run other
|
Simple NUMA policy support. It consists of a numactl program to run other
|
||||||
@ -72,6 +74,9 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
%{_mandir}/man3/*.3*
|
%{_mandir}/man3/*.3*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Thu Dec 07 2023 Paul Tohmas <relpeace@yeah.net> - 2.0.13-6
|
||||||
|
- fix segmentation fault with --offset and output wrong result with --verify
|
||||||
|
|
||||||
* Sat May 07 2022 zhouwenpei<zhouwenpei1@h-partners.com> - 2.0.13-5
|
* Sat May 07 2022 zhouwenpei<zhouwenpei1@h-partners.com> - 2.0.13-5
|
||||||
- fix crashes when using the "--touch" option
|
- fix crashes when using the "--touch" option
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user