Skip to contentSkip to conversation

getitimer02: add ITIMER_VIRTUAL timer error check

PATCH Applied Li Wang 2 participants 8 messages Oct 9, 2022 – Oct 20, 2022

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/2 getitimer02: add ITIMER_VIRTUAL timer error check

---
 testcases/kernel/syscalls/getitimer/getitimer02.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +3 -2
index 863e8e0a8..cd98dcce8 100644
@@ -27,8 +27,9 @@ static struct tcase {
        struct itimerval **val;
        int exp_errno;
 } tcases[] = {
-       {ITIMER_REAL, &invalid, EFAULT},
-       {-ITIMER_PROF, &value, EINVAL},
+       {ITIMER_REAL,    &invalid, EFAULT},
+       {ITIMER_VIRTUAL, &invalid, EFAULT},
+       {-ITIMER_PROF,   &value,   EINVAL},
 };
 
 static int sys_getitimer(int which, void *curr_value)
Signature · 5 lines
2.35.3


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

PATCH 2/2 setitimer03: convert to new API

Combine this EINVAL test into setitimer02 and add one additional ITIMER_VIRTUAL verification.

---
 runtest/syscalls                              |   1 -
 .../kernel/syscalls/setitimer/.gitignore      |   1 -
 .../kernel/syscalls/setitimer/setitimer02.c   |  30 +++-
 .../kernel/syscalls/setitimer/setitimer03.c   | 158 ------------------
 4 files changed, 24 insertions(+), 166 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/setitimer/setitimer03.c
runtest/syscalls +0 -1
index 61a7b7677..2d673836d 100644
@@ -1325,7 +1325,6 @@ sethostname03 sethostname03
 
 setitimer01 setitimer01
 setitimer02 setitimer02
-setitimer03 setitimer03
 
 setns01 setns01
 setns02 setns02
testcases/kernel/syscalls/setitimer/.gitignore +0 -1
index 048db9b31..35779a32c 100644
@@ -1,3 +1,2 @@
 /setitimer01
 /setitimer02
-/setitimer03
testcases/kernel/syscalls/setitimer/setitimer02.c +24 -6
index 9ac9ce1fa..ccba231c9 100644
@@ -18,17 +18,33 @@
 #include "tst_test.h"
 #include "lapi/syscalls.h"
 
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};
 
 static int sys_setitimer(int which, void *new_value, void *old_value)
 {
 	return tst_syscall(__NR_setitimer, which, new_value, old_value);
 }
 
-static void verify_setitimer(void)
+static void verify_setitimer(unsigned int i)
 {
-	TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (struct itimerval *)-1),
-	             EFAULT);
+        struct tcase *tc = &tcases[i];
+
+	if (tc->exp_errno == EFAULT)
+		*(tc->oval) = (struct itimerval *)-1;
+
+	TST_EXP_FAIL(sys_setitimer(tc->which, *(tc->val), *(tc->oval)),
+			tc->exp_errno);
 }
 
 static void setup(void)
@@ -40,10 +56,12 @@ static void setup(void)
 }
 
 static struct tst_test test = {
-	.test_all = verify_setitimer,
+        .tcnt = ARRAY_SIZE(tcases),
+	.test = verify_setitimer,
 	.setup = setup,
 	.bufs = (struct tst_buffers[]) {
-		{&value, .size = sizeof(struct itimerval)},
+		{&value,  .size = sizeof(struct itimerval)},
+		{&ovalue, .size = sizeof(struct itimerval)},
 		{}
 	}
 };
testcases/kernel/syscalls/setitimer/setitimer03.c deleted +0 -158

158 lines not on this page · raw message

Signature · 5 lines
2.35.3


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

Re: [LTP] [PATCH 2/2] setitimer03: convert to new API

Hello,

Quoted 2 lines · Li Wang

Combine this EINVAL test into setitimer02 and add one additional ITIMER_VIRTUAL verification.

EINVAL is not mentioned in the test description.

Quoted 36 lines
---
 runtest/syscalls                              |   1 -
 .../kernel/syscalls/setitimer/.gitignore      |   1 -
 .../kernel/syscalls/setitimer/setitimer02.c   |  30 +++-
 .../kernel/syscalls/setitimer/setitimer03.c   | 158 ------------------
 4 files changed, 24 insertions(+), 166 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/setitimer/setitimer03.c
runtest/syscalls +0 -1
index 61a7b7677..2d673836d 100644
@@ -1325,7 +1325,6 @@ sethostname03 sethostname03
 
 setitimer01 setitimer01
 setitimer02 setitimer02
-setitimer03 setitimer03
 
 setns01 setns01
 setns02 setns02
testcases/kernel/syscalls/setitimer/.gitignore +0 -1
index 048db9b31..35779a32c 100644
@@ -1,3 +1,2 @@
 /setitimer01
 /setitimer02
-/setitimer03
testcases/kernel/syscalls/setitimer/setitimer02.c +0 -0
index 9ac9ce1fa..ccba231c9 100644
@@ -18,17 +18,33 @@
 #include "tst_test.h"

testcases/kernel/syscalls/setitimer/setitimer02.c line 27

Quoted 10 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +7 -1
 #include "lapi/syscalls.h"
 
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;

There is a whitespace error here (see checkpatch/make check)

testcases/kernel/syscalls/setitimer/setitimer02.c line 32

Quoted 5 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -0
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};

Why do we need value and ovalue in the struct?

Quoted 5 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +0 -0
 static int sys_setitimer(int which, void *new_value, void *old_value)
 {
 	return tst_syscall(__NR_setitimer, which, new_value, old_value);
 }

testcases/kernel/syscalls/setitimer/setitimer02.c line 44

Quoted 10 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -3
 
-static void verify_setitimer(void)
+static void verify_setitimer(unsigned int i)
 {
-	TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (struct itimerval *)-1),
-	             EFAULT);
+        struct tcase *tc = &tcases[i];
+
+	if (tc->exp_errno == EFAULT)
+		*(tc->oval) = (struct itimerval *)-1;

Or, why do we use an if statement here instead of defining it in the struct?

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 2/2] setitimer03: convert to new API

Quoted 11 lines · Richard Palethorpe

testcases/kernel/syscalls/setitimer/setitimer02.c line 27

Quoted 8 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +7 -1
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;

There is a whitespace error here (see checkpatch/make check)

yes, thanks.

Quoted 9 lines

testcases/kernel/syscalls/setitimer/setitimer02.c line 32

Quoted 6 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -0
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};

Why do we need value and ovalue in the struct?

Becuase it does not allow parsing an invalid pointer address from a structure, we have to give a valid address which pointer to save an invalid address. Otherwise segement fault will be hit in execution.

And for the last test item, I don't want the invalid pointer to have a side effect disturbs the first invalid argument.

Quoted 12 lines

testcases/kernel/syscalls/setitimer/setitimer02.c

Quoted 11 lines

static int sys_setitimer(int which, void *new_value, void *old_value)

 {
      return tst_syscall(__NR_setitimer, which, new_value, old_value);

}

testcases/kernel/syscalls/setitimer/setitimer02.c +1 -2
-static void verify_setitimer(void)
+static void verify_setitimer(unsigned int i)
 {
-     TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (struct itimerval

*)-1),

Quoted 9 lines

testcases/kernel/syscalls/setitimer/setitimer02.c line 44

Quoted 5 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +4 -1
-                  EFAULT);
+        struct tcase *tc = &tcases[i];
+
+     if (tc->exp_errno == EFAULT)
+             *(tc->oval) = (struct itimerval *)-1;

Or, why do we use an if statement here instead of defining it in the struct?

Same above, that's why here explicitly reassign an invalid address.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw

Re: [LTP] [PATCH 2/2] setitimer03: convert to new API

Quoted 29 lines · Li Wang
Quoted 11 lines · Richard Palethorpe

testcases/kernel/syscalls/setitimer/setitimer02.c line 27

Quoted 8 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +7 -1
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;

There is a whitespace error here (see checkpatch/make check)

yes, thanks.

Quoted 9 lines

testcases/kernel/syscalls/setitimer/setitimer02.c line 32

Quoted 6 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -0
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};

Why do we need value and ovalue in the struct?

Quoted 5 lines

Becuase it does not allow parsing an invalid pointer address from a structure, we have to give a valid address which pointer to save an invalid address. Otherwise segement fault will be hit in execution.

On the other side, it also does not allow to initializer element is not constant in structure. So the two-level pointer is only the way I can make all things comprised here.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH 2/2] setitimer03: convert to new API

Hello,

Quoted 27 lines · Li Wang

On Thu, Oct 20, 2022 at 5:30 PM Li Wang <[email protected]> wrote:

testcases/kernel/syscalls/setitimer/setitimer02.c line 27

Quoted 8 lines · Richard Palethorpe
testcases/kernel/syscalls/setitimer/setitimer02.c +7 -1
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;

There is a whitespace error here (see checkpatch/make check)

yes, thanks.

testcases/kernel/syscalls/setitimer/setitimer02.c line 32

Quoted 5 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -0
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};

Why do we need value and ovalue in the struct?

Quoted 8 lines

Becuase it does not allow parsing an invalid pointer address from a structure, we have to give a valid address which pointer to save an invalid address. Otherwise segement fault will be hit in execution.

On the other side, it also does not allow to initializer element is not constant in structure. So the two-level pointer is only the way I can make all things comprised here.

I'm not sure what you mean and I don't understand why we need this struct at all. The following works and produces better output:

@@ -20,17 +20,6 @@

static struct itimerval *value, *ovalue;

-static struct tcase {

-       int which;
-       struct itimerval **val;
-       struct itimerval **oval;
-       int exp_errno;
-} tcases[] = {
-       {ITIMER_REAL,    &value, &ovalue, EFAULT},
-       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
-       {-ITIMER_PROF,   &value, &ovalue, EINVAL},

-};
-
static int sys_setitimer(int which, void *new_value, void *old_value)
{
return tst_syscall(__NR_setitimer, which, new_value, old_value);
@@ -38,13 +27,17 @@ static int sys_setitimer(int which, void *new_value, void *old_value)

static void verify_setitimer(unsigned int i)
{
- struct tcase *tc = &tcases[i];
-
- if (tc->exp_errno == EFAULT)
- *(tc->oval) = (struct itimerval *)-1;
-
- TST_EXP_FAIL(sys_setitimer(tc->which, *(tc->val), *(tc->oval)),
- tc->exp_errno);
+ switch (i) {
+ case 0:
+ TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT);
+ break;
+ case 1:
+ TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT);
+ break;
+ case 2:
+ TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL);
+ break;
+ }
}

static void setup(void)
@@ -56,7 +49,7 @@ static void setup(void)
}

static struct tst_test test = {
- .tcnt = ARRAY_SIZE(tcases),
+ .tcnt = 3,
.test = verify_setitimer,
.setup = setup,
.bufs = (struct tst_buffers[]) {

This prints

setitimer02.c:32: TPASS: sys_setitimer(ITIMER_REAL, value, (void *)-1) : EFAULT (14) setitimer02.c:35: TPASS: sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1) : EFAULT (14) setitimer02.c:38: TPASS: sys_setitimer(-ITIMER_PROF, value, ovalue) : EINVAL (22)

instead of

setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14) setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14) setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EINVAL (22)

The same values are passed to the syscall according to strace.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 2/2] setitimer03: convert to new API

Quoted 36 lines · Richard Palethorpe

Hello,

Quoted 32 lines · Li Wang

On Thu, Oct 20, 2022 at 5:30 PM Li Wang <[email protected]> wrote:

testcases/kernel/syscalls/setitimer/setitimer02.c line 27

Quoted 8 lines · Richard Palethorpe
testcases/kernel/syscalls/setitimer/setitimer02.c +7 -1
-static struct itimerval *value;
+static struct itimerval *value, *ovalue;
+
+static struct tcase {
+       int which;
+       struct itimerval **val;
+       struct itimerval **oval;
+       int exp_errno;

There is a whitespace error here (see checkpatch/make check)

yes, thanks.

testcases/kernel/syscalls/setitimer/setitimer02.c line 32

Quoted 5 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +5 -0
+} tcases[] = {
+       {ITIMER_REAL,    &value, &ovalue, EFAULT},
+       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
+       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
+};

Why do we need value and ovalue in the struct?

Becuase it does not allow parsing an invalid pointer address from a structure, we have to give a valid address which pointer to save an invalid address. Otherwise segement fault will be hit in execution.

Quoted 7 lines
Quoted 3 lines

On the other side, it also does not allow to initializer element is not constant in structure. So the two-level pointer is only the way I can make all things comprised here.

I'm not sure what you mean and I don't understand why we need this struct at all. The following works and produces better output:

Ok, I got your point. Previously I was stuck in thinking about how to keep the unified tcase struct for error testing.

Seems I should give up the fixed mindset.

static struct tcase {
     ...
} tcases[] = {
     ...
};
Quoted 83 lines
(quoted diff) +9 -18
@@ -20,17 +20,6 @@
 
 static struct itimerval *value, *ovalue;
 
-static struct tcase {
-       int which;
-       struct itimerval **val;
-       struct itimerval **oval;
-       int exp_errno;
-} tcases[] = {
-       {ITIMER_REAL,    &value, &ovalue, EFAULT},
-       {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
-       {-ITIMER_PROF,   &value, &ovalue, EINVAL},
-};
-
 static int sys_setitimer(int which, void *new_value, void *old_value)
 {
        return tst_syscall(__NR_setitimer, which, new_value, old_value);
@@ -38,13 +27,17 @@ static int sys_setitimer(int which, void *new_value,
 void *old_value)
 
 static void verify_setitimer(unsigned int i)
 {
-        struct tcase *tc = &tcases[i];
-
-       if (tc->exp_errno == EFAULT)
-               *(tc->oval) = (struct itimerval *)-1;
-
-       TST_EXP_FAIL(sys_setitimer(tc->which, *(tc->val), *(tc->oval)),
-                       tc->exp_errno);
+       switch (i) {
+       case 0:
+               TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void
 *)-1), EFAULT);
+               break;
+       case 1:
+               TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void
 *)-1), EFAULT);
+               break;
+       case 2:
+               TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue),

EINVAL);

testcases/kernel/syscalls/setitimer/setitimer02.c +3 -1
+               break;
+       }
 }
 
 static void setup(void)
@@ -56,7 +49,7 @@ static void setup(void)
 }
 
 static struct tst_test test = {
-        .tcnt = ARRAY_SIZE(tcases),
+        .tcnt = 3,
        .test = verify_setitimer,
        .setup = setup,
        .bufs = (struct tst_buffers[]) {

This prints

setitimer02.c:32: TPASS: sys_setitimer(ITIMER_REAL, value, (void *)-1) :
EFAULT (14)
setitimer02.c:35: TPASS: sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1) : EFAULT (14)
setitimer02.c:38: TPASS: sys_setitimer(-ITIMER_PROF, value, ovalue) :
EINVAL (22)

instead of

setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EINVAL (22)

The same values are passed to the syscall according to strace.

--
Thank you,
Richard.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw
In reply to Li Wang

Hello,

Merged, thanks!

Quoted 23 lines · Li Wang
---
 testcases/kernel/syscalls/getitimer/getitimer02.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +3 -2
index 863e8e0a8..cd98dcce8 100644
@@ -27,8 +27,9 @@ static struct tcase {
        struct itimerval **val;
        int exp_errno;
 } tcases[] = {
-       {ITIMER_REAL, &invalid, EFAULT},
-       {-ITIMER_PROF, &value, EINVAL},
+       {ITIMER_REAL,    &invalid, EFAULT},
+       {ITIMER_VIRTUAL, &invalid, EFAULT},
+       {-ITIMER_PROF,   &value,   EINVAL},
 };
 
 static int sys_getitimer(int which, void *curr_value)
Signature · 1 line
2.35.3
Signature · 5 lines
Thank you,
Richard.

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