Skip to contentSkip to conversation

unlink09: Fix open syscall flags

PATCH In review Avinesh Kumar 4 participants 8 messages Jun 1, 2024 – Jun 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unlink09: Fix open syscall flags

Fixes 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
---
 testcases/kernel/syscalls/unlink/unlink09.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unlink/unlink09.c +3 -3
index cc4b4a07e..405deb05f 100644
@@ -43,12 +43,12 @@ static void setup(void)
 {
 	int attr;
 
-	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
+	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_RDWR | O_CREAT, 0600);
 	SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
 	attr |= FS_IMMUTABLE_FL;
 	SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
 
-	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
+	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_RDWR | O_CREAT, 0600);
 	SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
 	attr |= FS_APPEND_FL;
 	SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
@@ -79,7 +79,7 @@ static void verify_unlink(unsigned int i)
 	/* If unlink() succeeded unexpectedly, test file should be restored. */
 	if (!TST_RET) {
 		if (tc->fd) {
-			*(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
+			*(tc->fd) = SAFE_OPEN(tc->filename, O_RDWR | O_CREAT, 0600);
 			if (tc->flag) {
 				SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS, &attr);
 				attr |= tc->flag;
Signature · 5 lines
2.45.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Avinesh,

Could you please amend the git commit message to explain why that flag would be needed?

Thanks,
Seb/

Quoted 47 lines · Avinesh Kumar
Fixes 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
---
 testcases/kernel/syscalls/unlink/unlink09.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unlink/unlink09.c +2 -2
index cc4b4a07e..405deb05f 100644
@@ -43,12 +43,12 @@ static void setup(void)
 {
        int attr;
 
-       fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
+       fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_RDWR | O_CREAT,
 0600);
        SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
        attr |= FS_IMMUTABLE_FL;
        SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
 
-       fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
+       fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_RDWR |
 O_CREAT, 0600);
        SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
        attr |= FS_APPEND_FL;
        SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
testcases/kernel/syscalls/unlink/unlink09.c +0 -0
@@ -79,7 +79,7 @@ static void verify_unlink(unsigned int i)
        /* If unlink() succeeded unexpectedly, test file should be

restored. */

        if (!TST_RET) {
                if (tc->fd) {
testcases/kernel/syscalls/unlink/unlink09.c +1 -1
-                       *(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
+                       *(tc->fd) = SAFE_OPEN(tc->filename, O_RDWR |
O_CREAT, 0600);
                        if (tc->flag) {
                                SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS,
&attr);
                                attr |= tc->flag;

--
2.45.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH 1/1 unlink09: Fix open syscall flags

In the SAFE_OPEN() calls, we missed to include any of the mandatory flags for open syscall: O_RDONLY, O_WRONLY, or O_RDWR

Fixes 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
---
 testcases/kernel/syscalls/unlink/unlink09.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unlink/unlink09.c +3 -3
index cc4b4a07e..405deb05f 100644
@@ -43,12 +43,12 @@ static void setup(void)
 {
 	int attr;
 
-	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
+	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_RDWR | O_CREAT, 0600);
 	SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
 	attr |= FS_IMMUTABLE_FL;
 	SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
 
-	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
+	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_RDWR | O_CREAT, 0600);
 	SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
 	attr |= FS_APPEND_FL;
 	SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
@@ -79,7 +79,7 @@ static void verify_unlink(unsigned int i)
 	/* If unlink() succeeded unexpectedly, test file should be restored. */
 	if (!TST_RET) {
 		if (tc->fd) {
-			*(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
+			*(tc->fd) = SAFE_OPEN(tc->filename, O_RDWR | O_CREAT, 0600);
 			if (tc->flag) {
 				SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS, &attr);
 				attr |= tc->flag;
Signature · 5 lines
2.45.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Andrea Cervesato on v1 1/1
#3 lore raw

Hi!

thanks for fixing the commit message and the test. According with the open() documentation an access flag is a must and that's one thing that makes this test wrong.

LGTM

Quoted 29 lines · Avinesh Kumar

In the SAFE_OPEN() calls, we missed to include any of the mandatory flags for open syscall: O_RDONLY, O_WRONLY, or O_RDWR

Fixes 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
---
  testcases/kernel/syscalls/unlink/unlink09.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unlink/unlink09.c +2 -2
index cc4b4a07e..405deb05f 100644
@@ -43,12 +43,12 @@ static void setup(void)
  {
  	int attr;
 
-	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
+	fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_RDWR | O_CREAT, 0600);
  	SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
  	attr |= FS_IMMUTABLE_FL;
  	SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
 
-	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
+	fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_RDWR | O_CREAT, 0600);
  	SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
  	attr |= FS_APPEND_FL;
  	SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);

testcases/kernel/syscalls/unlink/unlink09.c static void verify_unlink(unsigned int i) · line 85

Quoted 8 lines
testcases/kernel/syscalls/unlink/unlink09.c +1 -1
@@ -79,7 +79,7 @@ static void verify_unlink(unsigned int i)
  	/* If unlink() succeeded unexpectedly, test file should be restored. */
  	if (!TST_RET) {
  		if (tc->fd) {
-			*(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
+			*(tc->fd) = SAFE_OPEN(tc->filename, O_RDWR | O_CREAT, 0600);
  			if (tc->flag) {
  				SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS, &attr);
  				attr |= tc->flag;

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by
#4 lore raw

+1

Quoted 61 lines · Andrea Cervesato via ltp

Hi!

thanks for fixing the commit message and the test. According with the open() documentation an access flag
is a must and that's one thing that makes this test wrong.

LGTM

Review

Quoted 10 lines · Avinesh Kumar

In the SAFE_OPEN() calls, we missed to include any of the mandatory flags for open syscall: O_RDONLY, O_WRONLY, or O_RDWR

Fixes 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
---
  testcases/kernel/syscalls/unlink/unlink09.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/syscalls/unlink/unlink09.c

testcases/kernel/syscalls/unlink/unlink09.c static void setup(void) · line 46

Quoted 9 lines

index cc4b4a07e..405deb05f 100644

testcases/kernel/syscalls/unlink/unlink09.c +1 -1
@@ -43,12 +43,12 @@ static void setup(void)
  {
      int attr;
 
-     fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
+     fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_RDWR | O_CREAT,

0600);

testcases/kernel/syscalls/unlink/unlink09.c static void setup(void)

Quoted 6 lines
testcases/kernel/syscalls/unlink/unlink09.c +1 -1
      SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
      attr |= FS_IMMUTABLE_FL;
      SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
 
-     fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
+     fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_RDWR |

O_CREAT, 0600);

testcases/kernel/syscalls/unlink/unlink09.c static void verify_unlink(unsigned int i) · line 79

Quoted 5 lines
testcases/kernel/syscalls/unlink/unlink09.c +0 -0
      SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
      attr |= FS_APPEND_FL;
      SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
@@ -79,7 +79,7 @@ static void verify_unlink(unsigned int i)
      /* If unlink() succeeded unexpectedly, test file should be

restored. */

testcases/kernel/syscalls/unlink/unlink09.c static void verify_unlink(unsigned int i)

Quoted 4 lines
testcases/kernel/syscalls/unlink/unlink09.c +1 -1
      if (!TST_RET) {
              if (tc->fd) {
-                     *(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
+                     *(tc->fd) = SAFE_OPEN(tc->filename, O_RDWR |

O_CREAT, 0600);

testcases/kernel/syscalls/unlink/unlink09.c static void verify_unlink(unsigned int i) · line 84

Quoted 2 lines
testcases/kernel/syscalls/unlink/unlink09.c +0 -0
                      if (tc->flag) {
                              SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS,

&attr);

testcases/kernel/syscalls/unlink/unlink09.c static void verify_unlink(unsigned int i) · line 85

Quoted 1 line
testcases/kernel/syscalls/unlink/unlink09.c +0 -0
                              attr |= tc->flag;

Andrea

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi,

Unfortunately this patch is not working, due to the fact test requires to check if filesystem supports inode attributes. OPEN_CREAT() is more appropriate in this case and please refer to the following patch instead, since it's fixing the issue:

https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Andrea

Quoted 13 lines · Petr Vorel

Hi all,

I suppose with this fix Andrea's extra check is not needed, right? But sure, it would not harm anyway.

It'd be still interesting to know what exactly triggered the problem.

https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp