* [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX
2017-10-25 3:33 [LTP] [PATCH 1/2] syscalls/brk: change to unsigned long to avoid incr overflow Li Zhijian
@ 2017-10-25 3:33 ` Li Zhijian
0 siblings, 0 replies; 5+ messages in thread
From: Li Zhijian @ 2017-10-25 3:33 UTC (permalink / raw)
To: ltp
From: Li Zhijian <lizhijian@cn.fujitsu.com>
sometimes(some platforms), sbrk(0) will return a huge address(e.g
Beg_brk_val=94392102215680), it will lead to the request a huge
memory by brk(size>1T) which beyonds most host memory size
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: leishaoting <leist.fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/brk/brk01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/brk/brk01.c b/testcases/kernel/syscalls/brk/brk01.c
index b470ee7..22b9662 100644
--- a/testcases/kernel/syscalls/brk/brk01.c
+++ b/testcases/kernel/syscalls/brk/brk01.c
@@ -53,6 +53,7 @@ void setup();
void cleanup();
#define MAX_SIZE_LC 1000 /* loop count test will reach max size */
+#define MAX_INCR (UINT_MAX / 2)
char *TCID = "brk01";
int TST_TOTAL = 1;
@@ -83,6 +84,9 @@ int main(int ac, char **av)
if ((incr * 2) < 4096) /* make sure that process will grow */
incr += 4096 / 2;
+ // limit the requesting memory
+ incr = MIN(MAX_INCR, incr);
+
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH 1/2] syscalls/brk: change to unsigned long to avoid incr overflow
@ 2017-10-25 3:36 Li Zhijian
2017-10-25 3:36 ` [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX Li Zhijian
0 siblings, 1 reply; 5+ messages in thread
From: Li Zhijian @ 2017-10-25 3:36 UTC (permalink / raw)
To: ltp
Previously, incr is possible be overflowed at
81 incr = (Max_brk_byte_size - Beg_brk_val) / (MAX_SIZE_LC / 2);
103 nbrkpt = cur_brk_val + (2 * incr);
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: leishaoting <leist.fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/brk/brk01.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/brk/brk01.c b/testcases/kernel/syscalls/brk/brk01.c
index 9a36431..b470ee7 100644
--- a/testcases/kernel/syscalls/brk/brk01.c
+++ b/testcases/kernel/syscalls/brk/brk01.c
@@ -65,7 +65,7 @@ uintptr_t Beg_brk_val;
int main(int ac, char **av)
{
int lc;
- int incr;
+ unsigned long incr;
uintptr_t nbrkpt; /* new brk point value */
uintptr_t cur_brk_val; /* current size returned by sbrk */
uintptr_t aft_brk_val; /* current size returned by sbrk */
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX
2017-10-25 3:36 [LTP] [PATCH 1/2] syscalls/brk: change to unsigned long to avoid incr overflow Li Zhijian
@ 2017-10-25 3:36 ` Li Zhijian
2017-12-11 15:48 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Li Zhijian @ 2017-10-25 3:36 UTC (permalink / raw)
To: ltp
sometimes(some platforms), sbrk(0) will return a huge address(e.g
Beg_brk_val=94392102215680), it will lead to the request a huge
memory by brk(size>1T) which beyonds most host memory size
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: leishaoting <leist.fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/brk/brk01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/brk/brk01.c b/testcases/kernel/syscalls/brk/brk01.c
index b470ee7..22b9662 100644
--- a/testcases/kernel/syscalls/brk/brk01.c
+++ b/testcases/kernel/syscalls/brk/brk01.c
@@ -53,6 +53,7 @@ void setup();
void cleanup();
#define MAX_SIZE_LC 1000 /* loop count test will reach max size */
+#define MAX_INCR (UINT_MAX / 2)
char *TCID = "brk01";
int TST_TOTAL = 1;
@@ -83,6 +84,9 @@ int main(int ac, char **av)
if ((incr * 2) < 4096) /* make sure that process will grow */
incr += 4096 / 2;
+ // limit the requesting memory
+ incr = MIN(MAX_INCR, incr);
+
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX
2017-10-25 3:36 ` [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX Li Zhijian
@ 2017-12-11 15:48 ` Cyril Hrubis
2017-12-12 2:56 ` Li Zhijian
0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2017-12-11 15:48 UTC (permalink / raw)
To: ltp
Hi!
> sometimes(some platforms), sbrk(0) will return a huge address(e.g
> Beg_brk_val=94392102215680), it will lead to the request a huge
> memory by brk(size>1T) which beyonds most host memory size
I think that the code in the setup that determines the Max_brk_byte_size
does not make any sense to me, it seems to just multiply random value
(the initial break addres) by 4 and uses that as a base for increment. I
guess that it would be much better if we just choosen some multiple of
page size for the test.
Also the test should be running several iterations but we run only one
by default.
All in all I think that it would be much better if we rewrote the test
from scratch using the new test library instead of applying band aids
to problems that are broken by design.
In short, do you want to take on rewriting the test or should I do that?
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX
2017-12-11 15:48 ` Cyril Hrubis
@ 2017-12-12 2:56 ` Li Zhijian
0 siblings, 0 replies; 5+ messages in thread
From: Li Zhijian @ 2017-12-12 2:56 UTC (permalink / raw)
To: ltp
On 12/11/2017 11:48 PM, Cyril Hrubis wrote:
> Hi!
>> sometimes(some platforms), sbrk(0) will return a huge address(e.g
>> Beg_brk_val=94392102215680), it will lead to the request a huge
>> memory by brk(size>1T) which beyonds most host memory size
> I think that the code in the setup that determines the Max_brk_byte_size
> does not make any sense to me, it seems to just multiply random value
> (the initial break addres) by 4 and uses that as a base for increment. I
> guess that it would be much better if we just choosen some multiple of
> page size for the test.
agree
>
> Also the test should be running several iterations but we run only one
> by default.
>
> All in all I think that it would be much better if we rewrote the test
> from scratch using the new test library instead of applying band aids
> to problems that are broken by design.
>
> In short, do you want to take on rewriting the test or should I do that?
it's great if you can help to rewrite it. :)
Thanks
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-12 2:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-25 3:36 [LTP] [PATCH 1/2] syscalls/brk: change to unsigned long to avoid incr overflow Li Zhijian
2017-10-25 3:36 ` [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX Li Zhijian
2017-12-11 15:48 ` Cyril Hrubis
2017-12-12 2:56 ` Li Zhijian
-- strict thread matches above, loose matches on Subject: below --
2017-10-25 3:33 [LTP] [PATCH 1/2] syscalls/brk: change to unsigned long to avoid incr overflow Li Zhijian
2017-10-25 3:33 ` [LTP] [PATCH 2/2] syscalls/brk: limit the largest requesting memory to UINT_MAX Li Zhijian
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.