Skip to contentSkip to conversation

Fix bug caused by default umask

PATCH New Zou Wei 4 participants 13 messages Mar 30, 2020 – Mar 31, 2020

lore
Share & tools
lore

Zou Wei

author
#0 lore raw

v3 cover Fix bug caused by default umask

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear umask by umask(0) in setup().

Zou Wei (3):
security/dirtyc0w: Fix bug caused by default umask syscalls/fstat: Fix bug caused by default umask syscalls/statx01: Fix bug caused by default umask

 testcases/kernel/security/dirtyc0w/dirtyc0w.c | 2 ++
 testcases/kernel/syscalls/fstat/fstat02.c     | 2 ++
 testcases/kernel/syscalls/statx/statx01.c     | 2 ++
 3 files changed, 6 insertions(+)

--
2.6.2

author
#1 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

---
 testcases/kernel/security/dirtyc0w/dirtyc0w.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/security/dirtyc0w/dirtyc0w.c +2 -0
index a0a81b6..6455f9c 100644
@@ -45,6 +45,8 @@ static void setup(void)
 {
 	struct passwd *pw;
 
+	umask(0);
+
 	pw = SAFE_GETPWNAM("nobody");
 
 	nobody_uid = pw->pw_uid;

--
2.6.2

#2 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

Hi!

Quoted 2 lines

The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

What exactly fails in the dirtyc0w because of non-standard umask?

I can easily understand why fstat and statx fail, since we check the file permissions there. Ideally the failure should have been part of the patch description.

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

Hi!

Quoted 8 lines
Quoted 2 lines

The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

What exactly fails in the dirtyc0w because of non-standard umask?

I can easily understand why fstat and statx fail, since we check the file permissions there. Ideally the failure should have been part of the patch description.

Looking at the code I guess that the child fails to open the file created in parent before the setgid/setuid, something like this should really have been part of the patch description.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

Quoted 12 lines · Cyril Hrubis

Hi!

Quoted 7 lines
Quoted 2 lines

The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

What exactly fails in the dirtyc0w because of non-standard umask?

I can easily understand why fstat and statx fail, since we check the file permissions there. Ideally the failure should have been part of the patch description.

Looking at the code I guess that the child fails to open the file created in parent before the setgid/setuid, something like this should really have been part of the patch description.

Hi Cyril,

Right, some default mask drop the read permission of g/o and

nobody user cannot do read. :-)

Thanks,

Xiao Yang

#5 lore raw

[LTP] 答复: [PATCH v3 1/3] security/dirtyc0w: Fix bug caused by default umask

Hi Yang and Cyril,

Thank you so much for all your suggestions.

Best Regards
Zou Wei

-----????-----
???: Xiao Yang [mailto:[email protected]]
????: 2020?3?30? 20:34
???: Cyril Hrubis <[email protected]>; Zouwei (Samuel) <[email protected]> ??: [email protected]
??: Re: [LTP] [PATCH v3 1/3] security/dirtyc0w: Fix bug caused by default umask

Quoted 12 lines · Cyril Hrubis

Hi!

Quoted 7 lines
Quoted 2 lines

The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

What exactly fails in the dirtyc0w because of non-standard umask?

I can easily understand why fstat and statx fail, since we check the file permissions there. Ideally the failure should have been part of the patch description.

Looking at the code I guess that the child fails to open the file created in parent before the setgid/setuid, something like this should really have been part of the patch description.

Hi Cyril,

Right, some default mask drop the read permission of g/o and

nobody user cannot do read. :-)

Thanks,

Xiao Yang

#6 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

In reply to Cyril Hrubis

Hi Cyril, Petr

Just one question when reviewing this patch set.

I saw the umask set(e.g. set umask to 0 or 0022) is used by a lot of tests.

Is it necessary for metadata project to introduce .needs_umask?

Thanks,

Xiao Yang

Quoted 12 lines · Cyril Hrubis

Hi!

Quoted 7 lines
Quoted 2 lines

The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

What exactly fails in the dirtyc0w because of non-standard umask?

I can easily understand why fstat and statx fail, since we check the file permissions there. Ideally the failure should have been part of the patch description.

Looking at the code I guess that the child fails to open the file created in parent before the setgid/setuid, something like this should really have been part of the patch description.

#7 lore raw

PATCH v3 1/3 security/dirtyc0w: Fix bug caused by default umask

Hi!

Quoted 5 lines

Just one question when reviewing this patch set.

I saw the umask set(e.g. set umask to 0 or 0022) is used by a lot of tests.

Is it necessary for metadata project to introduce .needs_umask?

I do no think so.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#8 lore raw

PATCH v3 2/3 syscalls/fstat: Fix bug caused by default umask

In reply to Zou Wei

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

---
 testcases/kernel/syscalls/fstat/fstat02.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/fstat/fstat02.c +2 -0
index 4744560..c0229de 100644
@@ -72,6 +72,8 @@ static void setup(void)
 	user_id  = getuid();
 	group_id = getgid();
 
+	umask(0);
+
 	fildes = SAFE_OPEN(TESTFILE, O_WRONLY | O_CREAT, FILE_MODE);
 
 	if (tst_fill_file(TESTFILE, 'a', FILE_SIZE, 1))

--
2.6.2

author
#9 lore raw

PATCH v3 3/3 syscalls/statx01: Fix bug caused by default umask

In reply to Zou Wei

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear current umask by umask(0) in setup().

---
 testcases/kernel/syscalls/statx/statx01.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx01.c +2 -0
index 4f9d582..2358dd7 100644
@@ -148,6 +148,8 @@ static void setup(void)
 	char data_buff[SIZE];
 	int file_fd;
 
+	umask(0);
+
 	memset(data_buff, '@', sizeof(data_buff));
 
 	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR|O_CREAT, MODE);

--
2.6.2

#10 lore raw

v3 cover Fix bug caused by default umask

In reply to Zou Wei
Quoted 3 lines · Zou Wei

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear umask by umask(0) in setup().

Hi Zou,

Thanks for your patch set.
Did you find any other cases related with the same issue?

Thanks,
Xiao Yang

Quoted 15 lines

Zou Wei (3):
security/dirtyc0w: Fix bug caused by default umask syscalls/fstat: Fix bug caused by default umask syscalls/statx01: Fix bug caused by default umask

  testcases/kernel/security/dirtyc0w/dirtyc0w.c | 2 ++
  testcases/kernel/syscalls/fstat/fstat02.c     | 2 ++
  testcases/kernel/syscalls/statx/statx01.c     | 2 ++
  3 files changed, 6 insertions(+)

--
2.6.2

#11 lore raw

Hi Yang,

I downloaded the development version of ltp two weeks ago, ran the cases in the runtest directory, and analyzed all the failed cases. I found that these 3 cases have the umask issue.

Due to the limited time invested by individuals, it is possible that other cases with the same issue will not be discovered. I will analyze the other failed cases that have not been concluded further in the next few weeks.

Thanks for your suggestions and reviews.

Best Regards
Zou Wei
-----????-----
???: Xiao Yang [mailto:[email protected]] ????: 2020?3?30? 15:34
???: Zouwei (Samuel) <[email protected]>
??: [email protected]
??: Re: [LTP] [PATCH v3 0/3] Fix bug caused by default umask

Quoted 3 lines · Zou Wei

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear umask by umask(0) in setup().

Hi Zou,

Thanks for your patch set.
Did you find any other cases related with the same issue?

Thanks,
Xiao Yang

Quoted 15 lines

Zou Wei (3):
security/dirtyc0w: Fix bug caused by default umask syscalls/fstat: Fix bug caused by default umask syscalls/statx01: Fix bug caused by default umask

  testcases/kernel/security/dirtyc0w/dirtyc0w.c | 2 ++
  testcases/kernel/syscalls/fstat/fstat02.c     | 2 ++
  testcases/kernel/syscalls/statx/statx01.c     | 2 ++
  3 files changed, 6 insertions(+)

--
2.6.2

#12 lore raw
Quoted 7 lines · Zouwei (Samuel)

Hi Yang,

I downloaded the development version of ltp two weeks ago, ran the cases in the runtest directory, and analyzed all the failed cases. I found that these 3 cases have the umask issue.

Due to the limited time invested by individuals, it is possible that other cases with the same issue will not be discovered. I will analyze the other failed cases that have not been concluded further in the next few weeks.

Hi Zou,

Thanks, I have pushed the patch set.
Perhaps, you can fix all same umask issues by a single patch in future.

Thanks,
Xiao Yang

Quoted 43 lines

Thanks for your suggestions and reviews.

Best Regards
Zou Wei
-----????-----
???: Xiao Yang [mailto:[email protected]] ????: 2020?3?30? 15:34
???: Zouwei (Samuel)<[email protected]>
??: [email protected]
??: Re: [LTP] [PATCH v3 0/3] Fix bug caused by default umask

Quoted 3 lines · Zou Wei

v3:
The case is only successful when system default umask is 0022.
When default umask is 0077 or other values, should clear umask by umask(0) in setup().

Hi Zou,

Thanks for your patch set.
Did you find any other cases related with the same issue?

Thanks,
Xiao Yang

Quoted 15 lines

Zou Wei (3):
security/dirtyc0w: Fix bug caused by default umask syscalls/fstat: Fix bug caused by default umask syscalls/statx01: Fix bug caused by default umask

   testcases/kernel/security/dirtyc0w/dirtyc0w.c | 2 ++
   testcases/kernel/syscalls/fstat/fstat02.c     | 2 ++
   testcases/kernel/syscalls/statx/statx01.c     | 2 ++
   3 files changed, 6 insertions(+)

--
2.6.2