diff options
author | Ovidiu Panait <ovidiu.panait@windriver.com> | 2023-07-04 10:39:17 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-07-10 11:36:34 +0100 |
commit | 03a94d9a35bf56a4bdf447d3f7431d8af7b23722 (patch) | |
tree | 7ed776106104d60bad1d3c1906e0b1a072c947ac /meta/recipes-extended/mdadm/files | |
parent | 3c9c721be3002be2c81581615c72612748d2282a (diff) | |
download | poky-03a94d9a35bf56a4bdf447d3f7431d8af7b23722.tar.gz |
mdadm: fix segfaults when running ptests
Currently, some segfaults are reported when running ptest:
mdadm[12333]: segfault at 0 ip 00007fe855924060 sp 00007ffc4d6caf88 error 4 in libc.so.6[7f)
Code: d2 0f 84 b7 0f 00 00 48 83 fa 01 0f 84 b9 0f 00 00 49 89 d3 89 f1 89 f8 48 83 e1 3f 4f
Backport the following upstream commits to fix them:
679bd9508a30 ("DDF: Cleanup validate_geometry_ddf_container()")
2b93288a5650 ("DDF: Fix NULL pointer dereference in validate_geometry_ddf()")
548e9b916f86 ("mdadm/Grow: Fix use after close bug by closing after fork")
9ae62977b51d ("monitor: Avoid segfault when calling NULL get_bad_blocks")
The fixes are part of the "Bug fixes and testing improvments" patchset [1].
[1] https://www.spinics.net/lists/raid/msg70621.html
(From OE-Core rev: 9585009e3e505b361cd32b14e0e85e77e7822878)
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-extended/mdadm/files')
4 files changed, 337 insertions, 0 deletions
diff --git a/meta/recipes-extended/mdadm/files/0001-DDF-Cleanup-validate_geometry_ddf_container.patch b/meta/recipes-extended/mdadm/files/0001-DDF-Cleanup-validate_geometry_ddf_container.patch new file mode 100644 index 0000000000..cea435f83b --- /dev/null +++ b/meta/recipes-extended/mdadm/files/0001-DDF-Cleanup-validate_geometry_ddf_container.patch | |||
@@ -0,0 +1,148 @@ | |||
1 | From ca458f4dcc4de9403298f67543466ce4bbc8f8ae Mon Sep 17 00:00:00 2001 | ||
2 | From: Logan Gunthorpe <logang@deltatee.com> | ||
3 | Date: Wed, 22 Jun 2022 14:25:07 -0600 | ||
4 | Subject: [PATCH 1/4] DDF: Cleanup validate_geometry_ddf_container() | ||
5 | |||
6 | Move the function up so that the function declaration is not necessary | ||
7 | and remove the unused arguments to the function. | ||
8 | |||
9 | No functional changes are intended but will help with a bug fix in the | ||
10 | next patch. | ||
11 | |||
12 | Signed-off-by: Logan Gunthorpe <logang@deltatee.com> | ||
13 | Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | ||
14 | Signed-off-by: Jes Sorensen <jes@trained-monkey.org> | ||
15 | |||
16 | Upstream-Status: Backport | ||
17 | |||
18 | Reference to upstream patch: | ||
19 | https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=679bd9508a30 | ||
20 | |||
21 | Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> | ||
22 | --- | ||
23 | super-ddf.c | 88 ++++++++++++++++++++++++----------------------------- | ||
24 | 1 file changed, 39 insertions(+), 49 deletions(-) | ||
25 | |||
26 | diff --git a/super-ddf.c b/super-ddf.c | ||
27 | index 3f304cd..65cf727 100644 | ||
28 | --- a/super-ddf.c | ||
29 | +++ b/super-ddf.c | ||
30 | @@ -503,13 +503,6 @@ struct ddf_super { | ||
31 | static int load_super_ddf_all(struct supertype *st, int fd, | ||
32 | void **sbp, char *devname); | ||
33 | static int get_svd_state(const struct ddf_super *, const struct vcl *); | ||
34 | -static int | ||
35 | -validate_geometry_ddf_container(struct supertype *st, | ||
36 | - int level, int layout, int raiddisks, | ||
37 | - int chunk, unsigned long long size, | ||
38 | - unsigned long long data_offset, | ||
39 | - char *dev, unsigned long long *freesize, | ||
40 | - int verbose); | ||
41 | |||
42 | static int validate_geometry_ddf_bvd(struct supertype *st, | ||
43 | int level, int layout, int raiddisks, | ||
44 | @@ -3322,6 +3315,42 @@ static int reserve_space(struct supertype *st, int raiddisks, | ||
45 | return 1; | ||
46 | } | ||
47 | |||
48 | +static int | ||
49 | +validate_geometry_ddf_container(struct supertype *st, | ||
50 | + int level, int raiddisks, | ||
51 | + unsigned long long data_offset, | ||
52 | + char *dev, unsigned long long *freesize, | ||
53 | + int verbose) | ||
54 | +{ | ||
55 | + int fd; | ||
56 | + unsigned long long ldsize; | ||
57 | + | ||
58 | + if (level != LEVEL_CONTAINER) | ||
59 | + return 0; | ||
60 | + if (!dev) | ||
61 | + return 1; | ||
62 | + | ||
63 | + fd = dev_open(dev, O_RDONLY|O_EXCL); | ||
64 | + if (fd < 0) { | ||
65 | + if (verbose) | ||
66 | + pr_err("ddf: Cannot open %s: %s\n", | ||
67 | + dev, strerror(errno)); | ||
68 | + return 0; | ||
69 | + } | ||
70 | + if (!get_dev_size(fd, dev, &ldsize)) { | ||
71 | + close(fd); | ||
72 | + return 0; | ||
73 | + } | ||
74 | + close(fd); | ||
75 | + if (freesize) { | ||
76 | + *freesize = avail_size_ddf(st, ldsize >> 9, INVALID_SECTORS); | ||
77 | + if (*freesize == 0) | ||
78 | + return 0; | ||
79 | + } | ||
80 | + | ||
81 | + return 1; | ||
82 | +} | ||
83 | + | ||
84 | static int validate_geometry_ddf(struct supertype *st, | ||
85 | int level, int layout, int raiddisks, | ||
86 | int *chunk, unsigned long long size, | ||
87 | @@ -3347,11 +3376,9 @@ static int validate_geometry_ddf(struct supertype *st, | ||
88 | level = LEVEL_CONTAINER; | ||
89 | if (level == LEVEL_CONTAINER) { | ||
90 | /* Must be a fresh device to add to a container */ | ||
91 | - return validate_geometry_ddf_container(st, level, layout, | ||
92 | - raiddisks, *chunk, | ||
93 | - size, data_offset, dev, | ||
94 | - freesize, | ||
95 | - verbose); | ||
96 | + return validate_geometry_ddf_container(st, level, raiddisks, | ||
97 | + data_offset, dev, | ||
98 | + freesize, verbose); | ||
99 | } | ||
100 | |||
101 | if (!dev) { | ||
102 | @@ -3449,43 +3476,6 @@ static int validate_geometry_ddf(struct supertype *st, | ||
103 | return 1; | ||
104 | } | ||
105 | |||
106 | -static int | ||
107 | -validate_geometry_ddf_container(struct supertype *st, | ||
108 | - int level, int layout, int raiddisks, | ||
109 | - int chunk, unsigned long long size, | ||
110 | - unsigned long long data_offset, | ||
111 | - char *dev, unsigned long long *freesize, | ||
112 | - int verbose) | ||
113 | -{ | ||
114 | - int fd; | ||
115 | - unsigned long long ldsize; | ||
116 | - | ||
117 | - if (level != LEVEL_CONTAINER) | ||
118 | - return 0; | ||
119 | - if (!dev) | ||
120 | - return 1; | ||
121 | - | ||
122 | - fd = dev_open(dev, O_RDONLY|O_EXCL); | ||
123 | - if (fd < 0) { | ||
124 | - if (verbose) | ||
125 | - pr_err("ddf: Cannot open %s: %s\n", | ||
126 | - dev, strerror(errno)); | ||
127 | - return 0; | ||
128 | - } | ||
129 | - if (!get_dev_size(fd, dev, &ldsize)) { | ||
130 | - close(fd); | ||
131 | - return 0; | ||
132 | - } | ||
133 | - close(fd); | ||
134 | - if (freesize) { | ||
135 | - *freesize = avail_size_ddf(st, ldsize >> 9, INVALID_SECTORS); | ||
136 | - if (*freesize == 0) | ||
137 | - return 0; | ||
138 | - } | ||
139 | - | ||
140 | - return 1; | ||
141 | -} | ||
142 | - | ||
143 | static int validate_geometry_ddf_bvd(struct supertype *st, | ||
144 | int level, int layout, int raiddisks, | ||
145 | int *chunk, unsigned long long size, | ||
146 | -- | ||
147 | 2.39.1 | ||
148 | |||
diff --git a/meta/recipes-extended/mdadm/files/0002-DDF-Fix-NULL-pointer-dereference-in-validate_geometr.patch b/meta/recipes-extended/mdadm/files/0002-DDF-Fix-NULL-pointer-dereference-in-validate_geometr.patch new file mode 100644 index 0000000000..fafe88b49c --- /dev/null +++ b/meta/recipes-extended/mdadm/files/0002-DDF-Fix-NULL-pointer-dereference-in-validate_geometr.patch | |||
@@ -0,0 +1,56 @@ | |||
1 | From 14f110f0286d38e29ef5e51d7f72e049c2f18323 Mon Sep 17 00:00:00 2001 | ||
2 | From: Logan Gunthorpe <logang@deltatee.com> | ||
3 | Date: Wed, 22 Jun 2022 14:25:08 -0600 | ||
4 | Subject: [PATCH 2/4] DDF: Fix NULL pointer dereference in | ||
5 | validate_geometry_ddf() | ||
6 | |||
7 | A relatively recent patch added a call to validate_geometry() in | ||
8 | Manage_add() that has level=LEVEL_CONTAINER and chunk=NULL. | ||
9 | |||
10 | This causes some ddf tests to segfault which aborts the test suite. | ||
11 | |||
12 | To fix this, avoid dereferencing chunk when the level is | ||
13 | LEVEL_CONTAINER or LEVEL_NONE. | ||
14 | |||
15 | Fixes: 1f5d54a06df0 ("Manage: Call validate_geometry when adding drive to external container") | ||
16 | Signed-off-by: Logan Gunthorpe <logang@deltatee.com> | ||
17 | Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | ||
18 | Signed-off-by: Jes Sorensen <jes@trained-monkey.org> | ||
19 | |||
20 | Upstream-Status: Backport | ||
21 | |||
22 | Reference to upstream patch: | ||
23 | https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=2b93288a5650 | ||
24 | |||
25 | Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> | ||
26 | --- | ||
27 | super-ddf.c | 6 +++--- | ||
28 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
29 | |||
30 | diff --git a/super-ddf.c b/super-ddf.c | ||
31 | index 65cf727..3ef1293 100644 | ||
32 | --- a/super-ddf.c | ||
33 | +++ b/super-ddf.c | ||
34 | @@ -3369,9 +3369,6 @@ static int validate_geometry_ddf(struct supertype *st, | ||
35 | * If given BVDs, we make an SVD, changing all the GUIDs in the process. | ||
36 | */ | ||
37 | |||
38 | - if (*chunk == UnSet) | ||
39 | - *chunk = DEFAULT_CHUNK; | ||
40 | - | ||
41 | if (level == LEVEL_NONE) | ||
42 | level = LEVEL_CONTAINER; | ||
43 | if (level == LEVEL_CONTAINER) { | ||
44 | @@ -3381,6 +3378,9 @@ static int validate_geometry_ddf(struct supertype *st, | ||
45 | freesize, verbose); | ||
46 | } | ||
47 | |||
48 | + if (*chunk == UnSet) | ||
49 | + *chunk = DEFAULT_CHUNK; | ||
50 | + | ||
51 | if (!dev) { | ||
52 | mdu_array_info_t array = { | ||
53 | .level = level, | ||
54 | -- | ||
55 | 2.39.1 | ||
56 | |||
diff --git a/meta/recipes-extended/mdadm/files/0003-mdadm-Grow-Fix-use-after-close-bug-by-closing-after-.patch b/meta/recipes-extended/mdadm/files/0003-mdadm-Grow-Fix-use-after-close-bug-by-closing-after-.patch new file mode 100644 index 0000000000..a954ab027a --- /dev/null +++ b/meta/recipes-extended/mdadm/files/0003-mdadm-Grow-Fix-use-after-close-bug-by-closing-after-.patch | |||
@@ -0,0 +1,91 @@ | |||
1 | From bd064da1469a6a07331b076a0294a8c6c3c38526 Mon Sep 17 00:00:00 2001 | ||
2 | From: Logan Gunthorpe <logang@deltatee.com> | ||
3 | Date: Wed, 22 Jun 2022 14:25:09 -0600 | ||
4 | Subject: [PATCH 3/4] mdadm/Grow: Fix use after close bug by closing after fork | ||
5 | |||
6 | The test 07reshape-grow fails most of the time. But it succeeds around | ||
7 | 1 in 5 times. When it does succeed, it causes the tests to die because | ||
8 | mdadm has segfaulted. | ||
9 | |||
10 | The segfault was caused by mdadm attempting to repoen a file | ||
11 | descriptor that was already closed. The backtrace of the segfault | ||
12 | was: | ||
13 | |||
14 | #0 __strncmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:101 | ||
15 | #1 0x000056146e31d44b in devnm2devid (devnm=0x0) at util.c:956 | ||
16 | #2 0x000056146e31dab4 in open_dev_flags (devnm=0x0, flags=0) | ||
17 | at util.c:1072 | ||
18 | #3 0x000056146e31db22 in open_dev (devnm=0x0) at util.c:1079 | ||
19 | #4 0x000056146e3202e8 in reopen_mddev (mdfd=4) at util.c:2244 | ||
20 | #5 0x000056146e329f36 in start_array (mdfd=4, | ||
21 | mddev=0x7ffc55342450 "/dev/md0", content=0x7ffc55342860, | ||
22 | st=0x56146fc78660, ident=0x7ffc55342f70, best=0x56146fc6f5d0, | ||
23 | bestcnt=10, chosen_drive=0, devices=0x56146fc706b0, okcnt=5, | ||
24 | sparecnt=0, rebuilding_cnt=0, journalcnt=0, c=0x7ffc55342e90, | ||
25 | clean=1, avail=0x56146fc78720 "\001\001\001\001\001", | ||
26 | start_partial_ok=0, err_ok=0, was_forced=0) | ||
27 | at Assemble.c:1206 | ||
28 | #6 0x000056146e32c36e in Assemble (st=0x56146fc78660, | ||
29 | mddev=0x7ffc55342450 "/dev/md0", ident=0x7ffc55342f70, | ||
30 | devlist=0x56146fc6e2d0, c=0x7ffc55342e90) | ||
31 | at Assemble.c:1914 | ||
32 | #7 0x000056146e312ac9 in main (argc=11, argv=0x7ffc55343238) | ||
33 | at mdadm.c:1510 | ||
34 | |||
35 | The file descriptor was closed early in Grow_continue(). The noted commit | ||
36 | moved the close() call to close the fd above the fork which caused the | ||
37 | parent process to return with a closed fd. | ||
38 | |||
39 | This meant reshape_array() and Grow_continue() would return in the parent | ||
40 | with the fd forked. The fd would eventually be passed to reopen_mddev() | ||
41 | which returned an unhandled NULL from fd2devnm() which would then be | ||
42 | dereferenced in devnm2devid. | ||
43 | |||
44 | Fix this by moving the close() call below the fork. This appears to | ||
45 | fix the 07revert-grow test. While we're at it, switch to using | ||
46 | close_fd() to invalidate the file descriptor. | ||
47 | |||
48 | Fixes: 77b72fa82813 ("mdadm/Grow: prevent md's fd from being occupied during delayed time") | ||
49 | Cc: Alex Wu <alexwu@synology.com> | ||
50 | Cc: BingJing Chang <bingjingc@synology.com> | ||
51 | Cc: Danny Shih <dannyshih@synology.com> | ||
52 | Cc: ChangSyun Peng <allenpeng@synology.com> | ||
53 | Signed-off-by: Logan Gunthorpe <logang@deltatee.com> | ||
54 | Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | ||
55 | Signed-off-by: Jes Sorensen <jes@trained-monkey.org> | ||
56 | |||
57 | Upstream-Status: Backport | ||
58 | |||
59 | Reference to upstream patch: | ||
60 | https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=548e9b916f86 | ||
61 | |||
62 | Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> | ||
63 | --- | ||
64 | Grow.c | 4 +++- | ||
65 | 1 file changed, 3 insertions(+), 1 deletion(-) | ||
66 | |||
67 | diff --git a/Grow.c b/Grow.c | ||
68 | index 9c6fc95..a8e4e83 100644 | ||
69 | --- a/Grow.c | ||
70 | +++ b/Grow.c | ||
71 | @@ -3501,7 +3501,6 @@ started: | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | - close(fd); | ||
76 | /* Now we just need to kick off the reshape and watch, while | ||
77 | * handling backups of the data... | ||
78 | * This is all done by a forked background process. | ||
79 | @@ -3522,6 +3521,9 @@ started: | ||
80 | break; | ||
81 | } | ||
82 | |||
83 | + /* Close unused file descriptor in the forked process */ | ||
84 | + close_fd(&fd); | ||
85 | + | ||
86 | /* If another array on the same devices is busy, the | ||
87 | * reshape will wait for them. This would mean that | ||
88 | * the first section that we suspend will stay suspended | ||
89 | -- | ||
90 | 2.39.1 | ||
91 | |||
diff --git a/meta/recipes-extended/mdadm/files/0004-monitor-Avoid-segfault-when-calling-NULL-get_bad_blo.patch b/meta/recipes-extended/mdadm/files/0004-monitor-Avoid-segfault-when-calling-NULL-get_bad_blo.patch new file mode 100644 index 0000000000..72cb40f782 --- /dev/null +++ b/meta/recipes-extended/mdadm/files/0004-monitor-Avoid-segfault-when-calling-NULL-get_bad_blo.patch | |||
@@ -0,0 +1,42 @@ | |||
1 | From 2296a4a441b4b8546e2eb32403930f1bb8f3ee4a Mon Sep 17 00:00:00 2001 | ||
2 | From: Logan Gunthorpe <logang@deltatee.com> | ||
3 | Date: Wed, 22 Jun 2022 14:25:10 -0600 | ||
4 | Subject: [PATCH 4/4] monitor: Avoid segfault when calling NULL get_bad_blocks | ||
5 | |||
6 | Not all struct superswitch implement a get_bad_blocks() function, | ||
7 | yet mdmon seems to call it without checking for NULL and thus | ||
8 | occasionally segfaults in the test 10ddf-geometry. | ||
9 | |||
10 | Fix this by checking for NULL before calling it. | ||
11 | |||
12 | Signed-off-by: Logan Gunthorpe <logang@deltatee.com> | ||
13 | Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | ||
14 | Signed-off-by: Jes Sorensen <jes@trained-monkey.org> | ||
15 | |||
16 | Upstream-Status: Backport | ||
17 | |||
18 | Reference to upstream patch: | ||
19 | https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=9ae62977b51d | ||
20 | |||
21 | Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> | ||
22 | --- | ||
23 | monitor.c | 3 +++ | ||
24 | 1 file changed, 3 insertions(+) | ||
25 | |||
26 | diff --git a/monitor.c b/monitor.c | ||
27 | index afc3e50..8e43c0d 100644 | ||
28 | --- a/monitor.c | ||
29 | +++ b/monitor.c | ||
30 | @@ -312,6 +312,9 @@ static int check_for_cleared_bb(struct active_array *a, struct mdinfo *mdi) | ||
31 | struct md_bb *bb; | ||
32 | int i; | ||
33 | |||
34 | + if (!ss->get_bad_blocks) | ||
35 | + return -1; | ||
36 | + | ||
37 | /* | ||
38 | * Get a list of bad blocks for an array, then read list of | ||
39 | * acknowledged bad blocks from kernel and compare it against metadata | ||
40 | -- | ||
41 | 2.39.1 | ||
42 | |||