diff mbox series

[05/11] test_bitmap: skip user bitmap tests for !CONFIG_SET_FS

Message ID 20200817073212.830069-6-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/11] mem: remove duplicate ops for /dev/zero and /dev/null | expand

Commit Message

Christoph Hellwig Aug. 17, 2020, 7:32 a.m. UTC
We can't run the tests for userspace bitmap parsing if set_fs() doesn't
exist.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 lib/test_bitmap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Christophe Leroy Aug. 17, 2020, 7:50 a.m. UTC | #1
Le 17/08/2020 à 09:32, Christoph Hellwig a écrit :
> We can't run the tests for userspace bitmap parsing if set_fs() doesn't
> exist.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   lib/test_bitmap.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> index df903c53952bb9..49b1d25fbaf546 100644
> --- a/lib/test_bitmap.c
> +++ b/lib/test_bitmap.c
> @@ -365,6 +365,7 @@ static void __init __test_bitmap_parselist(int is_user)
>   	for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) {
>   #define ptest parselist_tests[i]
>   
> +#ifdef CONFIG_SET_FS

get_fs() and set_fs() have stubs for when an arch doesn't define them, 
so I this it would be cleaner if you were using 'if 
(IS_ENABLED(CONFIG_SET_FS) && is_user)`instead of an ifdefery in the 
middle of the if/else.

Christophe


>   		if (is_user) {
>   			mm_segment_t orig_fs = get_fs();
>   			size_t len = strlen(ptest.in);
> @@ -375,7 +376,9 @@ static void __init __test_bitmap_parselist(int is_user)
>   						    bmap, ptest.nbits);
>   			time = ktime_get() - time;
>   			set_fs(orig_fs);
> -		} else {
> +		} else
> +#endif /* CONFIG_SET_FS */
> +		{
>   			time = ktime_get();
>   			err = bitmap_parselist(ptest.in, bmap, ptest.nbits);
>   			time = ktime_get() - time;
> @@ -454,6 +457,7 @@ static void __init __test_bitmap_parse(int is_user)
>   	for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
>   		struct test_bitmap_parselist test = parse_tests[i];
>   
> +#ifdef CONFIG_SET_FS
>   		if (is_user) {
>   			size_t len = strlen(test.in);
>   			mm_segment_t orig_fs = get_fs();
> @@ -464,7 +468,9 @@ static void __init __test_bitmap_parse(int is_user)
>   						bmap, test.nbits);
>   			time = ktime_get() - time;
>   			set_fs(orig_fs);
> -		} else {
> +		} else
> +#endif /* CONFIG_SET_FS */
> +		{
>   			size_t len = test.flags & NO_LEN ?
>   				UINT_MAX : strlen(test.in);
>   			time = ktime_get();
>
Christoph Hellwig Aug. 17, 2020, 7:52 a.m. UTC | #2
On Mon, Aug 17, 2020 at 09:50:05AM +0200, Christophe Leroy wrote:
>
>
> Le 17/08/2020 à 09:32, Christoph Hellwig a écrit :
>> We can't run the tests for userspace bitmap parsing if set_fs() doesn't
>> exist.
>>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>>   lib/test_bitmap.c | 10 ++++++++--
>>   1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
>> index df903c53952bb9..49b1d25fbaf546 100644
>> --- a/lib/test_bitmap.c
>> +++ b/lib/test_bitmap.c
>> @@ -365,6 +365,7 @@ static void __init __test_bitmap_parselist(int is_user)
>>   	for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) {
>>   #define ptest parselist_tests[i]
>>   +#ifdef CONFIG_SET_FS
>
> get_fs() and set_fs() have stubs for when an arch doesn't define them, so I 
> this it would be cleaner if you were using 'if (IS_ENABLED(CONFIG_SET_FS) 
> && is_user)`instead of an ifdefery in the middle of the if/else.

No, I don't provide stubs in the prep patch, and that has been intentional
as I don't want this to spread much.  test_bitmap would be the only place
where they are somewht useful, and I just hope this test is eventually
getting rewritten to run in a normal user space context where the
uaccess tests can be resurrected.
Kees Cook Aug. 18, 2020, 7:43 p.m. UTC | #3
On Mon, Aug 17, 2020 at 09:32:06AM +0200, Christoph Hellwig wrote:
> We can't run the tests for userspace bitmap parsing if set_fs() doesn't
> exist.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kees Cook <keescook@chromium.org>
diff mbox series

Patch

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index df903c53952bb9..49b1d25fbaf546 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -365,6 +365,7 @@  static void __init __test_bitmap_parselist(int is_user)
 	for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) {
 #define ptest parselist_tests[i]
 
+#ifdef CONFIG_SET_FS
 		if (is_user) {
 			mm_segment_t orig_fs = get_fs();
 			size_t len = strlen(ptest.in);
@@ -375,7 +376,9 @@  static void __init __test_bitmap_parselist(int is_user)
 						    bmap, ptest.nbits);
 			time = ktime_get() - time;
 			set_fs(orig_fs);
-		} else {
+		} else
+#endif /* CONFIG_SET_FS */
+		{
 			time = ktime_get();
 			err = bitmap_parselist(ptest.in, bmap, ptest.nbits);
 			time = ktime_get() - time;
@@ -454,6 +457,7 @@  static void __init __test_bitmap_parse(int is_user)
 	for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
 		struct test_bitmap_parselist test = parse_tests[i];
 
+#ifdef CONFIG_SET_FS
 		if (is_user) {
 			size_t len = strlen(test.in);
 			mm_segment_t orig_fs = get_fs();
@@ -464,7 +468,9 @@  static void __init __test_bitmap_parse(int is_user)
 						bmap, test.nbits);
 			time = ktime_get() - time;
 			set_fs(orig_fs);
-		} else {
+		} else
+#endif /* CONFIG_SET_FS */
+		{
 			size_t len = test.flags & NO_LEN ?
 				UINT_MAX : strlen(test.in);
 			time = ktime_get();