Skip to contentSkip to conversation

setsockopt08: Handle ENOPROTOOPT even with compatible config

PATCH Superseded Richard Palethorpe 4 participants 7 messages Aug 12, 2021 – Aug 19, 2021 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 1/1 setsockopt08: Handle ENOPROTOOPT even with compatible config

One or more necessary modules can be missing even if they are present in the config.

---

V3:
* Use code suggested by Martin. Functionally it is the same as V2.

I'm not sure which is easier to read, but usually more indentation makes things worse. So this is better in that regard.

 .../kernel/syscalls/setsockopt/setsockopt08.c      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/setsockopt/setsockopt08.c +10 -4
index 33892f9b1..20abe85b4 100644
@@ -101,6 +101,8 @@ void setup(void)
 
 void run(void)
 {
+	const char *const res_fmt_str =
+		"setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)";
 	struct ipt_replace *ipt_replace = buffer;
 	struct ipt_entry *ipt_entry = &ipt_replace->entries[0];
 	struct xt_entry_match *xt_entry_match =
@@ -110,6 +112,7 @@ void run(void)
 	struct xt_entry_target *xt_entry_tgt =
 		((struct xt_entry_target *) (&ipt_entry->elems[0] + match_size));
 	int fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	int result;
 
 	xt_entry_match->u.user.match_size = (u_int16_t)match_size;
 	strcpy(xt_entry_match->u.user.name, "state");
@@ -126,10 +129,13 @@ void run(void)
 	ipt_replace->num_counters = 1;
 	ipt_replace->size = ipt_entry->next_offset;
 
-	TST_EXP_FAIL(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1),
-		     EINVAL,
-		     "setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)",
-		     fd, buffer);
+	TEST(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1));
+
+	if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
+		tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
+
+	result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
+	tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
 
 	SAFE_CLOSE(fd);
 }
Signature · 1 line
2.31.1
#2 lore raw

PATCH v3 1/1 setsockopt08: Handle ENOPROTOOPT even with compatible config

Hi,
small nit below but otherwise it looks good.

Quoted 30 lines · Richard Palethorpe

One or more necessary modules can be missing even if they are present in the config.

---

V3:
* Use code suggested by Martin. Functionally it is the same as V2.

I'm not sure which is easier to read, but usually more indentation makes things worse. So this is better in that regard.

 .../kernel/syscalls/setsockopt/setsockopt08.c      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/setsockopt/setsockopt08.c +2 -0
index 33892f9b1..20abe85b4 100644
@@ -101,6 +101,8 @@ void setup(void)
 
 void run(void)
 {
+	const char *const res_fmt_str =
+		"setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)";
 	struct ipt_replace *ipt_replace = buffer;
 	struct ipt_entry *ipt_entry = &ipt_replace->entries[0];
 	struct xt_entry_match *xt_entry_match =

testcases/kernel/syscalls/setsockopt/setsockopt08.c void run(void) · line 115

Quoted 4 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +1 -0
@@ -110,6 +112,7 @@ void run(void)
 	struct xt_entry_target *xt_entry_tgt =
 		((struct xt_entry_target *) (&ipt_entry->elems[0] + match_size));
 	int fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	int result;

Unused variable ^

Quoted 22 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +7 -4
 	xt_entry_match->u.user.match_size = (u_int16_t)match_size;
 	strcpy(xt_entry_match->u.user.name, "state");
@@ -126,10 +129,13 @@ void run(void)
 	ipt_replace->num_counters = 1;
 	ipt_replace->size = ipt_entry->next_offset;
 
-	TST_EXP_FAIL(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1),
-		     EINVAL,
-		     "setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)",
-		     fd, buffer);
+	TEST(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1));
+
+	if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
+		tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
+
+	result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
+	tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
 
 	SAFE_CLOSE(fd);
 }
Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#3 lore raw

PATCH v3 1/1 setsockopt08: Handle ENOPROTOOPT even with compatible config

Hello,

Quoted 4 lines · Martin Doucha

Hi,
small nit below but otherwise it looks good.

Cheers.

Quoted 24 lines · Richard Palethorpe
Quoted 22 lines

One or more necessary modules can be missing even if they are present in the config.

---

V3:
* Use code suggested by Martin. Functionally it is the same as V2.

I'm not sure which is easier to read, but usually more indentation makes things worse. So this is better in that regard.

 .../kernel/syscalls/setsockopt/setsockopt08.c      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/setsockopt/setsockopt08.c +0 -0
index 33892f9b1..20abe85b4 100644
@@ -101,6 +101,8 @@ void setup(void)
 
Quoted 14 lines

testcases/kernel/syscalls/setsockopt/setsockopt08.c void run(void) · line 115

Quoted 12 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +3 -0
 void run(void)
 {
+	const char *const res_fmt_str =
+		"setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)";
 	struct ipt_replace *ipt_replace = buffer;
 	struct ipt_entry *ipt_entry = &ipt_replace->entries[0];
 	struct xt_entry_match *xt_entry_match =
@@ -110,6 +112,7 @@ void run(void)
 	struct xt_entry_target *xt_entry_tgt =
 		((struct xt_entry_target *) (&ipt_entry->elems[0] + match_size));
 	int fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	int result;

Unused variable ^

It is used

Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +0 -0
 	xt_entry_match->u.user.match_size = (u_int16_t)match_size;
 	strcpy(xt_entry_match->u.user.name, "state");
@@ -126,10 +129,13 @@ void run(void)
 	ipt_replace->num_counters = 1;
 	ipt_replace->size = ipt_entry->next_offset;
 
Quoted 10 lines

testcases/kernel/syscalls/setsockopt/setsockopt08.c void run(void) · line 137

Quoted 10 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +6 -4
-	TST_EXP_FAIL(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1),
-		     EINVAL,
-		     "setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)",
-		     fd, buffer);
+	TEST(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1));
+
+	if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
+		tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
+
+	result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
        ^^^^^^
Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/setsockopt/setsockopt08.c +1 -0
+	tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
 
 	SAFE_CLOSE(fd);
 }
Signature · 2 lines
Thank you,
Richard.
#4 lore raw

PATCH v4 1/2 setsockopt08: Handle ENOPROTOOPT even with compatible config

In reply to Richard Palethorpe

One or more necessary modules can be missing even if they are present in the config.

---

V4: Add TINFO patch

 .../kernel/syscalls/setsockopt/setsockopt08.c      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/setsockopt/setsockopt08.c +10 -4
index 33892f9b1..20abe85b4 100644
@@ -101,6 +101,8 @@ void setup(void)
 
 void run(void)
 {
+	const char *const res_fmt_str =
+		"setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)";
 	struct ipt_replace *ipt_replace = buffer;
 	struct ipt_entry *ipt_entry = &ipt_replace->entries[0];
 	struct xt_entry_match *xt_entry_match =
@@ -110,6 +112,7 @@ void run(void)
 	struct xt_entry_target *xt_entry_tgt =
 		((struct xt_entry_target *) (&ipt_entry->elems[0] + match_size));
 	int fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	int result;
 
 	xt_entry_match->u.user.match_size = (u_int16_t)match_size;
 	strcpy(xt_entry_match->u.user.name, "state");
@@ -126,10 +129,13 @@ void run(void)
 	ipt_replace->num_counters = 1;
 	ipt_replace->size = ipt_entry->next_offset;
 
-	TST_EXP_FAIL(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1),
-		     EINVAL,
-		     "setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)",
-		     fd, buffer);
+	TEST(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1));
+
+	if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
+		tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
+
+	result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
+	tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
 
 	SAFE_CLOSE(fd);
 }
Signature · 1 line
2.31.1
#5 lore raw

PATCH v4 2/2 setsockopt08: Avoid confusion by removing TCONF

When not in compat mode this only tests that bad offsets result in EINVAL. When in compat mode, we also test for the vulnerability.

Therefor I view this as two tests. The TCONF was supposed to indicate the configuration didn't allow one of these tests. However it just caused confusion with multiple people asking me to change it to tst_brk.

So change it to TINFO.

---
 testcases/kernel/syscalls/setsockopt/setsockopt08.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/setsockopt/setsockopt08.c +1 -1
index 20abe85b4..1ffc69178 100644
@@ -91,7 +91,7 @@ static void *buffer;
 void setup(void)
 {
 	if (tst_kernel_bits() == 32 || sizeof(long) > 4) {
-		tst_res(TCONF,
+		tst_res(TINFO,
 			"The vulnerability was only present in 32-bit compat mode");
 	}
 
Signature · 1 line
2.31.1
#6 lore raw

PATCH v4 2/2 setsockopt08: Avoid confusion by removing TCONF

Quoted 8 lines · Richard Palethorpe via ltp

When not in compat mode this only tests that bad offsets result in EINVAL. When in compat mode, we also test for the vulnerability.

Therefor I view this as two tests. The TCONF was supposed to indicate the configuration didn't allow one of these tests. However it just caused confusion with multiple people asking me to change it to tst_brk.

Quoted 4 lines

So change it to TINFO.

---

Hi,
for both patches:

Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#7 lore raw

PATCH v4 2/2 setsockopt08: Avoid confusion by removing TCONF

Hi Richie, Martin,

Thanks both, patchset merged.

Kind regards,
Petr