* [PATCH v2] kexec: add resriction on the kexec_load
@ 2016-07-22 5:32 zhongjiang
2016-07-22 6:49 ` kbuild test robot
0 siblings, 1 reply; 7+ messages in thread
From: zhongjiang @ 2016-07-22 5:32 UTC (permalink / raw)
To: ebiederm, akpm; +Cc: kexec, linux-mm
From: zhong jiang <zhongjiang@huawei.com>
I hit the following question when run trinity in my system. The
kernel is 3.4 version. but the mainline have same question to be
solved. The root cause is the segment size is too large, it can
expand the most of the area or the whole memory, therefore, it
may waste an amount of time to abtain a useable page. and other
cases will block until the test case quit. at the some time,
OOM will come up.
Call Trace:
[<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
[<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
[<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
[<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
[<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
[<ffffffff810a1921>] sys_kexec_load+0x141/0x600
[<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
[<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
The patch just add condition on sanity_check_segment_list to
restriction the segment size.
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
kernel/kexec_core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 56b3ed0..b8751c3 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
int sanity_check_segment_list(struct kimage *image)
{
int result, i;
+ unsigned long total_segments = 0;
unsigned long nr_segments = image->nr_segments;
/*
@@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
return result;
}
+ /* Verity all segment size donnot exceed the specified size.
+ * if segment size from user space is too large, a large
+ * amount of time will be wasted when allocating page. so,
+ * softlockup may be come up.
+ */
+ for (i = 0; i < nr_segments; i++) {
+ if (image->segment[i].memsz > (totalram_pages / 2))
+ return result;
+
+ total += image->segment[i].memsz;
+ }
+
+ if (total > (totalram_pages / 2))
+ return result;
+
/*
* Verify we have good destination addresses. Normally
* the caller is responsible for making certain we don't
--
1.8.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2] kexec: add resriction on the kexec_load
@ 2016-07-22 5:36 zhongjiang
2016-07-22 19:58 ` Andrew Morton
0 siblings, 1 reply; 7+ messages in thread
From: zhongjiang @ 2016-07-22 5:36 UTC (permalink / raw)
To: ebiederm, akpm; +Cc: kexec, linux-mm
From: zhong jiang <zhongjiang@huawei.com>
I hit the following question when run trinity in my system. The
kernel is 3.4 version. but the mainline have same question to be
solved. The root cause is the segment size is too large, it can
expand the most of the area or the whole memory, therefore, it
may waste an amount of time to abtain a useable page. and other
cases will block until the test case quit. at the some time,
OOM will come up.
Call Trace:
[<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
[<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
[<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
[<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
[<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
[<ffffffff810a1921>] sys_kexec_load+0x141/0x600
[<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
[<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
The patch just add condition on sanity_check_segment_list to
restriction the segment size.
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
kernel/kexec_core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 56b3ed0..1f58824 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
int sanity_check_segment_list(struct kimage *image)
{
int result, i;
+ unsigned long total_segments = 0;
unsigned long nr_segments = image->nr_segments;
/*
@@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
return result;
}
+ /* Verity all segment size donnot exceed the specified size.
+ * if segment size from user space is too large, a large
+ * amount of time will be wasted when allocating page. so,
+ * softlockup may be come up.
+ */
+ for (i = 0; i < nr_segments; i++) {
+ if (image->segment[i].memsz > (totalram_pages / 2))
+ return result;
+
+ total_segments += image->segment[i].memsz;
+ }
+
+ if (total_segments > (totalram_pages / 2))
+ return result;
+
/*
* Verify we have good destination addresses. Normally
* the caller is responsible for making certain we don't
--
1.8.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kexec: add resriction on the kexec_load
2016-07-22 5:32 zhongjiang
@ 2016-07-22 6:49 ` kbuild test robot
0 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2016-07-22 6:49 UTC (permalink / raw)
To: zhongjiang; +Cc: kbuild-all, ebiederm, akpm, kexec, linux-mm
[-- Attachment #1: Type: text/plain, Size: 4347 bytes --]
Hi,
[auto build test ERROR on stable/master]
[also build test ERROR on v4.7-rc7]
[cannot apply to next-20160721]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/zhongjiang/kexec-add-resriction-on-the-kexec_load/20160722-143017
base: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git master
config: i386-defconfig (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All error/warnings (new ones prefixed by >>):
kernel/kexec_core.c: In function 'sanity_check_segment_list':
>> kernel/kexec_core.c:222:3: error: 'total' undeclared (first use in this function)
total += image->segment[i].memsz;
^~~~~
kernel/kexec_core.c:222:3: note: each undeclared identifier is reported only once for each function it appears in
>> kernel/kexec_core.c:151:16: warning: unused variable 'total_segments' [-Wunused-variable]
unsigned long total_segments = 0;
^~~~~~~~~~~~~~
vim +/total +222 kernel/kexec_core.c
145 gfp_t gfp_mask,
146 unsigned long dest);
147
148 int sanity_check_segment_list(struct kimage *image)
149 {
150 int result, i;
> 151 unsigned long total_segments = 0;
152 unsigned long nr_segments = image->nr_segments;
153
154 /*
155 * Verify we have good destination addresses. The caller is
156 * responsible for making certain we don't attempt to load
157 * the new image into invalid or reserved areas of RAM. This
158 * just verifies it is an address we can use.
159 *
160 * Since the kernel does everything in page size chunks ensure
161 * the destination addresses are page aligned. Too many
162 * special cases crop of when we don't do this. The most
163 * insidious is getting overlapping destination addresses
164 * simply because addresses are changed to page size
165 * granularity.
166 */
167 result = -EADDRNOTAVAIL;
168 for (i = 0; i < nr_segments; i++) {
169 unsigned long mstart, mend;
170
171 mstart = image->segment[i].mem;
172 mend = mstart + image->segment[i].memsz;
173 if ((mstart & ~PAGE_MASK) || (mend & ~PAGE_MASK))
174 return result;
175 if (mend >= KEXEC_DESTINATION_MEMORY_LIMIT)
176 return result;
177 }
178
179 /* Verify our destination addresses do not overlap.
180 * If we alloed overlapping destination addresses
181 * through very weird things can happen with no
182 * easy explanation as one segment stops on another.
183 */
184 result = -EINVAL;
185 for (i = 0; i < nr_segments; i++) {
186 unsigned long mstart, mend;
187 unsigned long j;
188
189 mstart = image->segment[i].mem;
190 mend = mstart + image->segment[i].memsz;
191 for (j = 0; j < i; j++) {
192 unsigned long pstart, pend;
193
194 pstart = image->segment[j].mem;
195 pend = pstart + image->segment[j].memsz;
196 /* Do the segments overlap ? */
197 if ((mend > pstart) && (mstart < pend))
198 return result;
199 }
200 }
201
202 /* Ensure our buffer sizes are strictly less than
203 * our memory sizes. This should always be the case,
204 * and it is easier to check up front than to be surprised
205 * later on.
206 */
207 result = -EINVAL;
208 for (i = 0; i < nr_segments; i++) {
209 if (image->segment[i].bufsz > image->segment[i].memsz)
210 return result;
211 }
212
213 /* Verity all segment size donnot exceed the specified size.
214 * if segment size from user space is too large, a large
215 * amount of time will be wasted when allocating page. so,
216 * softlockup may be come up.
217 */
218 for (i = 0; i < nr_segments; i++) {
219 if (image->segment[i].memsz > (totalram_pages / 2))
220 return result;
221
> 222 total += image->segment[i].memsz;
223 }
224
225 if (total > (totalram_pages / 2))
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 24863 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kexec: add resriction on the kexec_load
2016-07-22 5:36 [PATCH v2] kexec: add resriction on the kexec_load zhongjiang
@ 2016-07-22 19:58 ` Andrew Morton
2016-07-23 7:27 ` zhong jiang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andrew Morton @ 2016-07-22 19:58 UTC (permalink / raw)
To: zhongjiang; +Cc: ebiederm, linux-mm, kexec
On Fri, 22 Jul 2016 13:36:22 +0800 zhongjiang <zhongjiang@huawei.com> wrote:
> From: zhong jiang <zhongjiang@huawei.com>
>
> I hit the following question when run trinity in my system. The
> kernel is 3.4 version. but the mainline have same question to be
> solved. The root cause is the segment size is too large, it can
> expand the most of the area or the whole memory, therefore, it
> may waste an amount of time to abtain a useable page. and other
> cases will block until the test case quit. at the some time,
> OOM will come up.
>
> Call Trace:
> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>
> The patch just add condition on sanity_check_segment_list to
> restriction the segment size.
>
> ...
>
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
> int sanity_check_segment_list(struct kimage *image)
> {
> int result, i;
> + unsigned long total_segments = 0;
> unsigned long nr_segments = image->nr_segments;
>
> /*
> @@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
> return result;
> }
>
> + /* Verity all segment size donnot exceed the specified size.
> + * if segment size from user space is too large, a large
> + * amount of time will be wasted when allocating page. so,
> + * softlockup may be come up.
> + */
> + for (i = 0; i < nr_segments; i++) {
> + if (image->segment[i].memsz > (totalram_pages / 2))
> + return result;
> +
> + total_segments += image->segment[i].memsz;
> + }
> +
> + if (total_segments > (totalram_pages / 2))
> + return result;
> +
> /*
> * Verify we have good destination addresses. Normally
> * the caller is responsible for making certain we don't
This needed a few adjustments for pending changes in linux-next's
sanity_check_segment_list(). Mainly s/return result/return -EINVAL/.
I also tweaked the patch changelog. Please check.
From: zhong jiang <zhongjiang@huawei.com>
Subject: kexec: add restriction on kexec_load() segment sizes
I hit the following issue when run trinity in my system. The kernel is
3.4 version, but mainline has the same issue.
The root cause is that the segment size is too large so the kerenl spends
too long trying to allocate a page. Other cases will block until the test
case quits. Also, OOM conditions will occur.
Call Trace:
[<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
[<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
[<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
[<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
[<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
[<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
[<ffffffff810a1921>] sys_kexec_load+0x141/0x600
[<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
[<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
The patch chnages sanity_check_segment_list() to verify that no segment is
larger than half of memory.
Link: http://lkml.kernel.org/r/1469165782-13193-1-git-send-email-zhongjiang@huawei.com
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/kexec_core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff -puN kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load kernel/kexec_core.c
--- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load
+++ a/kernel/kexec_core.c
@@ -154,6 +154,7 @@ static struct page *kimage_alloc_page(st
int sanity_check_segment_list(struct kimage *image)
{
int i;
+ unsigned long total_segments = 0;
unsigned long nr_segments = image->nr_segments;
/*
@@ -214,6 +215,21 @@ int sanity_check_segment_list(struct kim
return -EINVAL;
}
+ /* Verity all segment size donnot exceed the specified size.
+ * if segment size from user space is too large, a large
+ * amount of time will be wasted when allocating page. so,
+ * softlockup may be come up.
+ */
+ for (i = 0; i < nr_segments; i++) {
+ if (image->segment[i].memsz > (totalram_pages / 2))
+ return -EINVAL;
+
+ total_segments += image->segment[i].memsz;
+ }
+
+ if (total_segments > (totalram_pages / 2))
+ return -EINVAL;
+
/*
* Verify we have good destination addresses. Normally
* the caller is responsible for making certain we don't
_
also I tweaked the comments a bit:
--- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load-fix
+++ a/kernel/kexec_core.c
@@ -215,10 +215,10 @@ int sanity_check_segment_list(struct kim
return -EINVAL;
}
- /* Verity all segment size donnot exceed the specified size.
- * if segment size from user space is too large, a large
- * amount of time will be wasted when allocating page. so,
- * softlockup may be come up.
+ /*
+ * Verify that no segment is larger than half of memory. If a segment
+ * from userspace is too large, a large amount of time will be wasted
+ * allocating pages, which can cause a soft lockup.
*/
for (i = 0; i < nr_segments; i++) {
if (image->segment[i].memsz > (totalram_pages / 2))
_
Eric ack?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kexec: add resriction on the kexec_load
2016-07-22 19:58 ` Andrew Morton
@ 2016-07-23 7:27 ` zhong jiang
2016-07-23 11:23 ` zhong jiang
2016-07-23 13:37 ` zhong jiang
2 siblings, 0 replies; 7+ messages in thread
From: zhong jiang @ 2016-07-23 7:27 UTC (permalink / raw)
To: Andrew Morton; +Cc: ebiederm, linux-mm, kexec
On 2016/7/23 3:58, Andrew Morton wrote:
> On Fri, 22 Jul 2016 13:36:22 +0800 zhongjiang <zhongjiang@huawei.com> wrote:
>
>> From: zhong jiang <zhongjiang@huawei.com>
>>
>> I hit the following question when run trinity in my system. The
>> kernel is 3.4 version. but the mainline have same question to be
>> solved. The root cause is the segment size is too large, it can
>> expand the most of the area or the whole memory, therefore, it
>> may waste an amount of time to abtain a useable page. and other
>> cases will block until the test case quit. at the some time,
>> OOM will come up.
>>
>> Call Trace:
>> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
>> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
>> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
>> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
>> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
>> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
>> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
>> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>>
>> The patch just add condition on sanity_check_segment_list to
>> restriction the segment size.
>>
>> ...
>>
>> --- a/kernel/kexec_core.c
>> +++ b/kernel/kexec_core.c
>> @@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
>> int sanity_check_segment_list(struct kimage *image)
>> {
>> int result, i;
>> + unsigned long total_segments = 0;
>> unsigned long nr_segments = image->nr_segments;
>>
>> /*
>> @@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
>> return result;
>> }
>>
>> + /* Verity all segment size donnot exceed the specified size.
>> + * if segment size from user space is too large, a large
>> + * amount of time will be wasted when allocating page. so,
>> + * softlockup may be come up.
>> + */
>> + for (i = 0; i < nr_segments; i++) {
>> + if (image->segment[i].memsz > (totalram_pages / 2))
>> + return result;
>> +
>> + total_segments += image->segment[i].memsz;
>> + }
>> +
>> + if (total_segments > (totalram_pages / 2))
>> + return result;
>> +
>> /*
>> * Verify we have good destination addresses. Normally
>> * the caller is responsible for making certain we don't
> This needed a few adjustments for pending changes in linux-next's
> sanity_check_segment_list(). Mainly s/return result/return -EINVAL/.
> I also tweaked the patch changelog. Please check.
>
> From: zhong jiang <zhongjiang@huawei.com>
> Subject: kexec: add restriction on kexec_load() segment sizes
>
> I hit the following issue when run trinity in my system. The kernel is
> 3.4 version, but mainline has the same issue.
>
> The root cause is that the segment size is too large so the kerenl spends
> too long trying to allocate a page. Other cases will block until the test
> case quits. Also, OOM conditions will occur.
>
> Call Trace:
> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>
> The patch chnages sanity_check_segment_list() to verify that no segment is
> larger than half of memory.
>
> Link: http://lkml.kernel.org/r/1469165782-13193-1-git-send-email-zhongjiang@huawei.com
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> kernel/kexec_core.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff -puN kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load kernel/kexec_core.c
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load
> +++ a/kernel/kexec_core.c
> @@ -154,6 +154,7 @@ static struct page *kimage_alloc_page(st
> int sanity_check_segment_list(struct kimage *image)
> {
> int i;
> + unsigned long total_segments = 0;
> unsigned long nr_segments = image->nr_segments;
>
> /*
> @@ -214,6 +215,21 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> + /* Verity all segment size donnot exceed the specified size.
> + * if segment size from user space is too large, a large
> + * amount of time will be wasted when allocating page. so,
> + * softlockup may be come up.
> + */
> + for (i = 0; i < nr_segments; i++) {
> + if (image->segment[i].memsz > (totalram_pages / 2))
> + return -EINVAL;
> +
> + total_segments += image->segment[i].memsz;
> + }
> +
> + if (total_segments > (totalram_pages / 2))
> + return -EINVAL;
> +
> /*
> * Verify we have good destination addresses. Normally
> * the caller is responsible for making certain we don't
> _
>
>
>
>
> also I tweaked the comments a bit:
>
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load-fix
> +++ a/kernel/kexec_core.c
> @@ -215,10 +215,10 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> - /* Verity all segment size donnot exceed the specified size.
> - * if segment size from user space is too large, a large
> - * amount of time will be wasted when allocating page. so,
> - * softlockup may be come up.
> + /*
> + * Verify that no segment is larger than half of memory. If a segment
> + * from userspace is too large, a large amount of time will be wasted
> + * allocating pages, which can cause a soft lockup.
> */
> for (i = 0; i < nr_segments; i++) {
> if (image->segment[i].memsz > (totalram_pages / 2))
> _
>
>
> Eric ack?
>
> .
>
Thanks, the comment is exact.
v1->v2 : the modification was suggested by Eric.
I guess that he is offline. I have another patch about kexec is still not conclusion.
Thanks
zhongjiang
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kexec: add resriction on the kexec_load
2016-07-22 19:58 ` Andrew Morton
2016-07-23 7:27 ` zhong jiang
@ 2016-07-23 11:23 ` zhong jiang
2016-07-23 13:37 ` zhong jiang
2 siblings, 0 replies; 7+ messages in thread
From: zhong jiang @ 2016-07-23 11:23 UTC (permalink / raw)
To: Andrew Morton; +Cc: ebiederm, linux-mm, kexec
On 2016/7/23 3:58, Andrew Morton wrote:
> On Fri, 22 Jul 2016 13:36:22 +0800 zhongjiang <zhongjiang@huawei.com> wrote:
>
>> From: zhong jiang <zhongjiang@huawei.com>
>>
>> I hit the following question when run trinity in my system. The
>> kernel is 3.4 version. but the mainline have same question to be
>> solved. The root cause is the segment size is too large, it can
>> expand the most of the area or the whole memory, therefore, it
>> may waste an amount of time to abtain a useable page. and other
>> cases will block until the test case quit. at the some time,
>> OOM will come up.
>>
>> Call Trace:
>> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
>> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
>> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
>> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
>> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
>> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
>> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
>> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>>
>> The patch just add condition on sanity_check_segment_list to
>> restriction the segment size.
>>
>> ...
>>
>> --- a/kernel/kexec_core.c
>> +++ b/kernel/kexec_core.c
>> @@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
>> int sanity_check_segment_list(struct kimage *image)
>> {
>> int result, i;
>> + unsigned long total_segments = 0;
>> unsigned long nr_segments = image->nr_segments;
>>
>> /*
>> @@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
>> return result;
>> }
>>
>> + /* Verity all segment size donnot exceed the specified size.
>> + * if segment size from user space is too large, a large
>> + * amount of time will be wasted when allocating page. so,
>> + * softlockup may be come up.
>> + */
>> + for (i = 0; i < nr_segments; i++) {
>> + if (image->segment[i].memsz > (totalram_pages / 2))
>> + return result;
>> +
>> + total_segments += image->segment[i].memsz;
>> + }
>> +
>> + if (total_segments > (totalram_pages / 2))
>> + return result;
>> +
>> /*
>> * Verify we have good destination addresses. Normally
>> * the caller is responsible for making certain we don't
> This needed a few adjustments for pending changes in linux-next's
> sanity_check_segment_list(). Mainly s/return result/return -EINVAL/.
> I also tweaked the patch changelog. Please check.
>
> From: zhong jiang <zhongjiang@huawei.com>
> Subject: kexec: add restriction on kexec_load() segment sizes
>
> I hit the following issue when run trinity in my system. The kernel is
> 3.4 version, but mainline has the same issue.
>
> The root cause is that the segment size is too large so the kerenl spends
> too long trying to allocate a page. Other cases will block until the test
> case quits. Also, OOM conditions will occur.
>
> Call Trace:
> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>
> The patch chnages sanity_check_segment_list() to verify that no segment is
> larger than half of memory.
>
> Link: http://lkml.kernel.org/r/1469165782-13193-1-git-send-email-zhongjiang@huawei.com
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> kernel/kexec_core.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff -puN kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load kernel/kexec_core.c
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load
> +++ a/kernel/kexec_core.c
> @@ -154,6 +154,7 @@ static struct page *kimage_alloc_page(st
> int sanity_check_segment_list(struct kimage *image)
> {
> int i;
> + unsigned long total_segments = 0;
> unsigned long nr_segments = image->nr_segments;
>
> /*
> @@ -214,6 +215,21 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> + /* Verity all segment size donnot exceed the specified size.
> + * if segment size from user space is too large, a large
> + * amount of time will be wasted when allocating page. so,
> + * softlockup may be come up.
> + */
> + for (i = 0; i < nr_segments; i++) {
> + if (image->segment[i].memsz > (totalram_pages / 2))
> + return -EINVAL;
> +
> + total_segments += image->segment[i].memsz;
> + }
> +
> + if (total_segments > (totalram_pages / 2))
> + return -EINVAL;
> +
> /*
> * Verify we have good destination addresses. Normally
> * the caller is responsible for making certain we don't
> _
>
>
>
>
> also I tweaked the comments a bit:
>
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load-fix
> +++ a/kernel/kexec_core.c
> @@ -215,10 +215,10 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> - /* Verity all segment size donnot exceed the specified size.
> - * if segment size from user space is too large, a large
> - * amount of time will be wasted when allocating page. so,
> - * softlockup may be come up.
>
> for (i = 0; i < nr_segments; i++) {
> if (image->segment[i].memsz > (totalram_pages / 2))
> _
>
>
> Eric ack?
>
> .
>
Hi, Andrew
when I review the patch, I find the following question. please fix it by rebaseing.
Subject: [PATCH] kexec: fix the add restriction on the kexec_load
Because segments size is in bytes, while totalram_pages is in pages
so we should fix it.
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
kernel/kexec_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 22e41a1..88cf3f9 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -216,13 +216,13 @@ int sanity_check_segment_list(struct kimage *image)
* allocating pages, which can cause a soft lockup.
*/
for (i = 0; i < nr_segments; i++) {
- if (image->segment[i].memsz > (totalram_pages / 2))
+ if (image->segment[i].memsz > (totalram_pages << 12) / 2)
return result;
total_segments += image->segment[i].memsz;
}
- if (total_segments > (totalram_pages / 2))
+ if (total_segments > (totalram_pages << 12) / 2)
return result;
/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kexec: add resriction on the kexec_load
2016-07-22 19:58 ` Andrew Morton
2016-07-23 7:27 ` zhong jiang
2016-07-23 11:23 ` zhong jiang
@ 2016-07-23 13:37 ` zhong jiang
2 siblings, 0 replies; 7+ messages in thread
From: zhong jiang @ 2016-07-23 13:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: ebiederm, linux-mm, kexec
On 2016/7/23 3:58, Andrew Morton wrote:
> On Fri, 22 Jul 2016 13:36:22 +0800 zhongjiang <zhongjiang@huawei.com> wrote:
>
>> From: zhong jiang <zhongjiang@huawei.com>
>>
>> I hit the following question when run trinity in my system. The
>> kernel is 3.4 version. but the mainline have same question to be
>> solved. The root cause is the segment size is too large, it can
>> expand the most of the area or the whole memory, therefore, it
>> may waste an amount of time to abtain a useable page. and other
>> cases will block until the test case quit. at the some time,
>> OOM will come up.
>>
>> Call Trace:
>> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
>> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
>> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
>> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
>> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
>> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
>> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
>> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
>> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>>
>> The patch just add condition on sanity_check_segment_list to
>> restriction the segment size.
>>
>> ...
>>
>> --- a/kernel/kexec_core.c
>> +++ b/kernel/kexec_core.c
>> @@ -148,6 +148,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
>> int sanity_check_segment_list(struct kimage *image)
>> {
>> int result, i;
>> + unsigned long total_segments = 0;
>> unsigned long nr_segments = image->nr_segments;
>>
>> /*
>> @@ -209,6 +210,21 @@ int sanity_check_segment_list(struct kimage *image)
>> return result;
>> }
>>
>> + /* Verity all segment size donnot exceed the specified size.
>> + * if segment size from user space is too large, a large
>> + * amount of time will be wasted when allocating page. so,
>> + * softlockup may be come up.
>> + */
>> + for (i = 0; i < nr_segments; i++) {
>> + if (image->segment[i].memsz > (totalram_pages / 2))
>> + return result;
>> +
>> + total_segments += image->segment[i].memsz;
>> + }
>> +
>> + if (total_segments > (totalram_pages / 2))
>> + return result;
>> +
>> /*
>> * Verify we have good destination addresses. Normally
>> * the caller is responsible for making certain we don't
> This needed a few adjustments for pending changes in linux-next's
> sanity_check_segment_list(). Mainly s/return result/return -EINVAL/.
> I also tweaked the patch changelog. Please check.
>
> From: zhong jiang <zhongjiang@huawei.com>
> Subject: kexec: add restriction on kexec_load() segment sizes
>
> I hit the following issue when run trinity in my system. The kernel is
> 3.4 version, but mainline has the same issue.
>
> The root cause is that the segment size is too large so the kerenl spends
> too long trying to allocate a page. Other cases will block until the test
> case quits. Also, OOM conditions will occur.
>
> Call Trace:
> [<ffffffff81106eac>] __alloc_pages_nodemask+0x14c/0x8f0
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8124c2be>] ? trace_hardirqs_on_thunk+0x3a/0x3c
> [<ffffffff8113e5ef>] alloc_pages_current+0xaf/0x120
> [<ffffffff810a0da0>] kimage_alloc_pages+0x10/0x60
> [<ffffffff810a15ad>] kimage_alloc_control_pages+0x5d/0x270
> [<ffffffff81027e85>] machine_kexec_prepare+0xe5/0x6c0
> [<ffffffff810a0d52>] ? kimage_free_page_list+0x52/0x70
> [<ffffffff810a1921>] sys_kexec_load+0x141/0x600
> [<ffffffff8115e6b0>] ? vfs_write+0x100/0x180
> [<ffffffff8145fbd9>] system_call_fastpath+0x16/0x1b
>
> The patch chnages sanity_check_segment_list() to verify that no segment is
> larger than half of memory.
>
> Link: http://lkml.kernel.org/r/1469165782-13193-1-git-send-email-zhongjiang@huawei.com
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> kernel/kexec_core.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff -puN kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load kernel/kexec_core.c
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load
> +++ a/kernel/kexec_core.c
> @@ -154,6 +154,7 @@ static struct page *kimage_alloc_page(st
> int sanity_check_segment_list(struct kimage *image)
> {
> int i;
> + unsigned long total_segments = 0;
> unsigned long nr_segments = image->nr_segments;
>
> /*
> @@ -214,6 +215,21 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> + /* Verity all segment size donnot exceed the specified size.
> + * if segment size from user space is too large, a large
> + * amount of time will be wasted when allocating page. so,
> + * softlockup may be come up.
> + */
> + for (i = 0; i < nr_segments; i++) {
> + if (image->segment[i].memsz > (totalram_pages / 2))
> + return -EINVAL;
> +
> + total_segments += image->segment[i].memsz;
> + }
> +
> + if (total_segments > (totalram_pages / 2))
> + return -EINVAL;
> +
> /*
> * Verify we have good destination addresses. Normally
> * the caller is responsible for making certain we don't
> _
>
>
>
>
> also I tweaked the comments a bit:
>
> --- a/kernel/kexec_core.c~kexec-add-resriction-on-the-kexec_load-fix
> +++ a/kernel/kexec_core.c
> @@ -215,10 +215,10 @@ int sanity_check_segment_list(struct kim
> return -EINVAL;
> }
>
> - /* Verity all segment size donnot exceed the specified size.
> - * if segment size from user space is too large, a large
> - * amount of time will be wasted when allocating page. so,
> - * softlockup may be come up.
> + /*
> + * Verify that no segment is larger than half of memory. If a segment
> + * from userspace is too large, a large amount of time will be wasted
> + * allocating pages, which can cause a soft lockup.
> */
> for (i = 0; i < nr_segments; i++) {
> if (image->segment[i].memsz > (totalram_pages / 2))
> _
>
>
> Eric ack?
>
> .
>
I am so sorry, I think that page_shift is more suitable than 12. it should like as follow.
if (total_segments > (totalram_pages << PAGE_SHIFT) / 2)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-07-23 13:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-22 5:36 [PATCH v2] kexec: add resriction on the kexec_load zhongjiang
2016-07-22 19:58 ` Andrew Morton
2016-07-23 7:27 ` zhong jiang
2016-07-23 11:23 ` zhong jiang
2016-07-23 13:37 ` zhong jiang
-- strict thread matches above, loose matches on Subject: below --
2016-07-22 5:32 zhongjiang
2016-07-22 6:49 ` kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).