Skip to contentSkip to conversation

Netlink helper functions refactoring + CVE 2023-31248

PATCH In review Martin Doucha 4 participants 13 messages Nov 14, 2023 – Nov 15, 2023 Library code

lore
Share & tools
lore
#0 lore raw

v2 cover Netlink helper functions refactoring + CVE 2023-31248

Let's refactor the rtnetlink helper functions for generic use where possible. The Netlink context structure can be used for other Netlink protocols like NETLINK_CRYPTO or NETLINK_NETFILTER. One of the exceptions is
the NETLINK_KOBJECT_UEVENT protocol which returns raw data without the usual headers.

The first patch replaces the tst_rtnl_* and RTNL_* prefix with tst_netlink_* and NETLINK_* respectively to signify that the functions can be used for generic netlink communication. The attribute handling functions are specific to the NETLINK_ROUTE protocol so they keep the old prefix. The fourth patch adds new attribute handling functions for generic struct nlattr.

The third patch replaces old netlink send/receive helper functions with the context-based helpers in crypto test code.

Finally, add test for CVE 2023-31248 which was promised in v1.

Martin Doucha (5):
tst_rtnetlink: Refactor helper function for generic use tst_netlink_destroy_context(): Allow safely passing NULL context
crypto: Replace old netlink helper functions with netlink contexts
tst_netlink: Add helper functions for handling generic attributes Add test for CVE 2023-31248

 doc/C-Test-Network-API.asciidoc         | 159 +++++++++---------
 include/tst_crypto.h                    |  69 +-------
 include/tst_netdevice.h                 |   8 +-
 include/tst_netlink.h                   | 195 +++++++++++++---------
 include/tst_rtnetlink.h                 | 108 ------------
 lib/tst_crypto.c                        |  90 ++--------
 lib/tst_netdevice.c                     | 115 ++++++-------
 lib/{tst_rtnetlink.c => tst_netlink.c}  | 170 ++++++++++++++-----
 testcases/cve/tcindex01.c               |  16 +-
 testcases/kernel/crypto/crypto_user01.c |  58 +++----
 testcases/kernel/crypto/crypto_user02.c |  17 +-
 testcases/kernel/crypto/pcrypt_aead01.c |  10 +-
 testcases/network/iptables/Makefile     |   2 +-
 testcases/network/iptables/nft02.c      | 211 ++++++++++++++++++++++++
 14 files changed, 667 insertions(+), 561 deletions(-)
 delete mode 100644 include/tst_rtnetlink.h
 rename lib/{tst_rtnetlink.c => tst_netlink.c} (63%)
 create mode 100644 testcases/network/iptables/nft02.c
Signature · 5 lines
2.42.0


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

PATCH v2 1/5 tst_rtnetlink: Refactor helper function for generic use

The netlink context structure can be used for any netlink protocol, not just for NETLINK_ROUTE. Change the RTNL prefix to NETLINK on all helper functions which don't use NETLINK_ROUTE features and add a new protocol parameter to tst_netlink_create_context().

---

Changes since v1: Rebased

 doc/C-Test-Network-API.asciidoc | 155 ++++++++++++++++----------------
 include/tst_rtnetlink.h         |  85 +++++++++---------
 lib/tst_netdevice.c             |  93 +++++++++----------
 lib/tst_rtnetlink.c             |  83 ++++++++---------
 testcases/cve/tcindex01.c       |   2 +-
 5 files changed, 212 insertions(+), 206 deletions(-)
doc/C-Test-Network-API.asciidoc +79 -76
index 3bf2a1f8a..25e4bbd18 100644
@@ -143,7 +143,7 @@ static void setup(void)
 When opening a localhost socket isn't enough and the test needs special device
 or routing configuration, the netdevice library can create the required network
 setup without calling external programs. Internally, the netdevice functions
-use a rtnetlink socket to communicate with the kernel.
+use a netlink socket to communicate with the kernel.
 
 All of these functions will call +tst_brk()+ on failure, unless stated
 otherwise. Error values described below are returned only during test cleanup
@@ -274,12 +274,12 @@ static void setup(void)
 }
 -------------------------------------------------------------------------------
 
-3 rtnetlink API
+3 Netlink API
 ---------------
 
 +#include "tst_rtnetlink.h"+
 
-The rtnetlink library provides helper functions for constructing and sending
+The netlink library provides helper functions for constructing and sending
 arbitrary messages and parsing kernel responses.
 
 All of the functions below will call +tst_brk()+ on failure, unless stated
@@ -291,7 +291,7 @@ stage.
 
 [source,c]
 -------------------------------------------------------------------------------
-struct tst_rtnl_context;
+struct tst_netlink_context;
 
 struct tst_rtnl_attr_list {
 	unsigned short type;
@@ -300,7 +300,7 @@ struct tst_rtnl_attr_list {
 	const struct tst_rtnl_attr_list *sublist;
 };
 
-struct tst_rtnl_message {
+struct tst_netlink_message {
 	struct nlmsghdr *header;
 	struct nlmsgerr *err;
 	void *payload;
@@ -308,10 +308,10 @@ struct tst_rtnl_message {
 };
 -------------------------------------------------------------------------------
 
-+struct tst_rtnl_context+ is an opaque rtnetlink socket with buffer for
++struct tst_netlink_context+ is an opaque netlink socket with buffer for
 constructing and sending arbitrary messages using the functions described
-below. Create a new context using +RTNL_CREATE_CONTEXT()+, then free it using
-+RTNL_DESTROY_CONTEXT()+ when you're done with it.
+below. Create a new context using +NETLINK_CREATE_CONTEXT()+, then free it
+using +NETLINK_DESTROY_CONTEXT()+ when you're done with it.
 
 +struct tst_rtnl_attr_list+ is a helper structure for defining complex
 rtnetlink message attribute payloads, including nested attribute lists. Every
@@ -331,10 +331,10 @@ negative +len+.
   to the +len+ field. If you do not want to add nested attributes, set
   +sublist+ to +NULL+.
 
-+struct tst_rtnl_message+ is a structure holding partially parsed rtnetlink
-messages received from the kernel. +RTNL_RECV()+ returns an array of these
++struct tst_netlink_message+ is a structure holding partially parsed netlink
+messages received from the kernel. +NETLINK_RECV()+ returns an array of these
 structures with the last item having +NULL+ in the +header+ field. Call
-+RTNL_FREE_MESSAGE()+ to free a message list returned by +RTNL_RECV()+.
++NETLINK_FREE_MESSAGE()+ to free a message list returned by +NETLINK_RECV()+.
 
 - +header+ is the netlink header structure of the message. +NULL+ in the header
   field terminates a list of messages.
@@ -349,83 +349,86 @@ structures with the last item having +NULL+ in the +header+ field. Call
 3.2 Sending and receiving messages
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-- +struct tst_rtnl_context *RTNL_CREATE_CONTEXT(void)+ – Creates a new
-  rtnetlink communication context for use with the functions described below.
-  Returns +NULL+ on error.
+- +struct tst_netlink_context *NETLINK_CREATE_CONTEXT(int protocol)+ – Creates
+  a new netlink communication context with given netlink protocol for use
+  with the functions described below. Returns +NULL+ on error.
 
-- +void RTNL_FREE_MESSAGE(struct tst_rtnl_message *msg)+ – Frees an array of
-  messages returned by +RTNL_RECV()+.
+- +void NETLINK_FREE_MESSAGE(struct tst_netlink_message *msg)+ – Frees
+  an array of messages returned by +NETLINK_RECV()+.
 
-- +void RTNL_DESTROY_CONTEXT(struct tst_rtnl_context *ctx)+ – Closes a
-  communication context created by +RTNL_CREATE_CONTEXT()+.
+- +void NETLINK_DESTROY_CONTEXT(struct tst_netlink_context *ctx)+ – Closes a
+  communication context created by +NETLINK_CREATE_CONTEXT()+.
 
-- +int RTNL_SEND(struct tst_rtnl_context *ctx)+ – Sends all messages waiting
-  in +ctx+ buffer to the kernel. If there are multiple messages to send, a new
-  +NLMSG_DONE+ message will be added automatically. Returns the number of
-  bytes sent on success. Return 0 or negative value on error.
+- +int NETLINK_SEND(struct tst_netlink_context *ctx)+ – Sends all messages
+  waiting in +ctx+ buffer to the kernel. If there are multiple messages
+  to send, a new +NLMSG_DONE+ message will be added automatically. Returns
+  the number of bytes sent on success. Return 0 or negative value on error.
 
-- +int RTNL_SEND_VALIDATE(struct tst_rtnl_context *ctx)+ – Sends all messages
-  just like +RTNL_SEND()+, then receives the response from the kernel and
-  validates results of requests sent with the +NLM_F_ACK+ flag. This function
-  calls +tst_brk()+ as usual if communication fails but it will return error
-  status without terminating the test if one of the received messages contains
-  error code. See +RTNL_CHECK_ACKS()+ below for explanation of the return
-  value.
+- +int NETLINK_SEND_VALIDATE(struct tst_netlink_context *ctx)+ – Sends all
+  messages just like +NETLINK_SEND()+, then receives the response from
+  the kernel and validates results of requests sent with the +NLM_F_ACK+ flag.
+  This function calls +tst_brk()+ as usual if communication fails but it will
+  return error status without terminating the test if one of the received
+  messages contains error code. See +NETLINK_CHECK_ACKS()+ below for
+  explanation of the return value.
 
-- +int RTNL_WAIT(struct tst_rtnl_context *ctx)+ – Waits until data becomes
-  available to read from the rtnetlink socket (timeout: 1 second). Returns 1
+- +int NETLINK_WAIT(struct tst_netlink_context *ctx)+ – Waits until data becomes
+  available to read from the netlink socket (timeout: 1 second). Returns 1
   if there is data to read, 0 on timeout or -1 on error.
 
-- +struct tst_rtnl_message *RTNL_RECV(struct tst_rtnl_context *ctx)+ – Receives
-  rtnetlink messages from the kernel. The messages are received in non-blocking
-  mode so calling +RTNL_WAIT()+ first is recommended. Returns an array of
-  partially parsed messages terminated by an item with +NULL+ in the +header+
-  field. On error or when there are no messages to receive, returns +NULL+.
-  Call +RTNL_FREE_MESSAGE()+ to free the returned data.
-
-- +int RTNL_CHECK_ACKS(struct tst_rtnl_context *ctx, struct tst_rtnl_message
-  *response)+ – Validate results of requests sent with the +NLM_F_ACK+ flag.
-  Do not call +RTNL_ADD_MESSAGE()+ between +RTNL_SEND()+ and
-  +RTNL_CHECK_ACKS()+ because it will reset the state of +ctx+ and prevent
-  result validation. Returns 1 if all messages sent with the +NLM_F_ACK+ flag
-  have a corresponding message in +response+ and the error code is 0. If any
-  of the expected response messages is missing, this function will call
-  +tst_brk()+ (or return 0 during test cleanup phase). If any of the response
-  messages has non-zero error code, this function will return 0 and store the
-  first non-zero error code in global variable +tst_rtnl_errno+ (sign-flipped
-  just like regular libc +errno+).
+- +struct tst_netlink_message *NETLINK_RECV(struct tst_netlink_context *ctx)+ –
+  Receives netlink messages from the kernel. The messages are received
+  in non-blocking mode so calling +NETLINK_WAIT()+ first is recommended.
+  Returns an array of partially parsed messages terminated by an item with
+  +NULL+ in the +header+ field. On error or when there are no messages
+  to receive, returns +NULL+. Call +NETLINK_FREE_MESSAGE()+ to free
+  the returned data.
+
+- +int NETLINK_CHECK_ACKS(struct tst_netlink_context *ctx,
+  struct tst_netlink_message *response)+ – Validate results of requests sent
+  with the +NLM_F_ACK+ flag. Do not call +NETLINK_ADD_MESSAGE()+ between
+  +NETLINK_SEND()+ and +NETLINK_CHECK_ACKS()+ because it will reset the state
+  of +ctx+ and prevent result validation. Returns 1 if all messages sent
+  with the +NLM_F_ACK+ flag have a corresponding message in +response+ and
+  the error code is 0. If any of the expected response messages is missing,
+  this function will call +tst_brk()+ (or return 0 during test cleanup phase).
+  If any of the response messages has non-zero error code, this function will
+  return 0 and store the first non-zero error code in global variable
+  +tst_netlink_errno+ (sign-flipped just like regular libc +errno+).
 
 3.3 Creating messages
 ~~~~~~~~~~~~~~~~~~~~~
 
-- +int RTNL_ADD_MESSAGE(struct tst_rtnl_context *ctx, const struct nlmsghdr
-  *header, const void *payload, size_t payload_size)+ – Adds new rtnetlink
-  message to +ctx+ buffer. You need to provide message +header+ and optional
-  +payload+. +payload_size+ is the size of +payload+ data in bytes. If you
-  don't want to add any payload data, set +payload+ to +NULL+ and
+- +int NETLINK_ADD_MESSAGE(struct tst_netlink_context *ctx, const struct
+  nlmsghdr *header, const void *payload, size_t payload_size)+ – Adds new
+  netlink message to +ctx+ buffer. You need to provide message +header+ and
+  optional +payload+. +payload_size+ is the size of +payload+ data in bytes.
+  If you don't want to add any payload data, set +payload+ to +NULL+ and
   +payload_size+ to 0. This function will automatically fill the +nlmsg_len+,
   +nlmsg_seq+ and +nlmsg_pid+ fields of the new message header. You don't need
   to set those. It'll also automatically add +NLM_F_MULTI+ flag when needed.
   Returns 1 on success, 0 on error. Note that the first call of
-  +RTNL_ADD_MESSAGE()+ after +RTNL_SEND()+ will reset the state of +ctx+
-  and +RTNL_CHECK_ACKS()+ will not work correctly until the next +RTNL_SEND()+.
-
-- +int RTNL_ADD_ATTR(struct tst_rtnl_context *ctx, unsigned short type, const
-  void *data, unsigned short len)+ – Adds new attribute to the last message
-  in +ctx+ buffer. See +RTNL_ADD_MESSAGE()+. You need to provide attribute
-  +type+ which will be stored in +struct rtattr.rta_type+, optional payload
-  +data+ and payload size +len+ in bytes. If you don't want to add any payload,
-  set +data+ to +NULL+ and +len+ to 0. Returns 1 on success, 0 on error.
-
-- +int RTNL_ADD_ATTR_STRING(struct tst_rtnl_context *ctx, unsigned short type,
-  const char *data)+ – Adds new string attribute to the last message in +ctx+
-  buffer. Parameters and return value are the same as for +RTNL_ADD_ATTR()+,
-  except the payload length is calculated using +strlen()+.
-
-- +int RTNL_ADD_ATTR_LIST(struct tst_rtnl_context *ctx, const struct
+  +NETLINK_ADD_MESSAGE()+ after +NETLINK_SEND()+ will reset the state of +ctx+
+  and +NETLINK_CHECK_ACKS()+ will not work correctly until the next
+  +NETLINK_SEND()+.
+
+- +int RTNL_ADD_ATTR(struct tst_netlink_context *ctx, unsigned short type,
+  const void *data, unsigned short len)+ – Adds new attribute to the last
+  message in +ctx+ buffer. See +NETLINK_ADD_MESSAGE()+. You need to provide
+  attribute +type+ which will be stored in +struct rtattr.rta_type+, optional
+  payload +data+ and payload size +len+ in bytes. If you don't want to add any
+  payload, set +data+ to +NULL+ and +len+ to 0. Returns 1 on success,
+  0 on error.
+
+- +int RTNL_ADD_ATTR_STRING(struct tst_netlink_context *ctx, unsigned short
+  type, const char *data)+ – Adds new string attribute to the last message
+  in +ctx+ buffer. Parameters and return value are the same as for
+  +RTNL_ADD_ATTR()+, except the payload length is calculated using +strlen()+.
+
+- +int RTNL_ADD_ATTR_LIST(struct tst_netlink_context *ctx, const struct
   tst_rtnl_attr_list *list)+ – Adds a list of attributes to the last message
   in +ctx+ buffer. See description of +struct tst_rtnl_attr_list+ and
-  +RTNL_ADD_MESSAGE()+ above.  Returns the number of added attributes on
+  +NETLINK_ADD_MESSAGE()+ above.  Returns the number of added attributes on
   success (nested attributes are not counted), -1 on error.
 
 Example Usage
@@ -447,7 +450,7 @@ Example Usage
 
 void setup(void)
 {
-	struct tst_rtnl_context *ctx;
+	struct tst_netlink_context *ctx;
 	int index, ret;
 	in_addr_t addr;
 
@@ -465,12 +468,12 @@ void setup(void)
 	index = NETDEV_INDEX_BY_NAME("ltp_veth1");
 	info.ifa_index = index;
 
-	ctx = RTNL_CREATE_CONTEXT();
-	RTNL_ADD_MESSAGE(ctx, &header, &info, sizeof(info));
+	ctx = NETLINK_CREATE_CONTEXT(NETLINK_ROUTE);
+	NETLINK_ADD_MESSAGE(ctx, &header, &info, sizeof(info));
 	addr = inet_addr("192.168.123.45");
 	RTNL_ADD_ATTR(ctx, IFA_LOCAL, &addr, sizeof(addr));
-	ret = RTNL_SEND_VALIDATE(ctx);
-	RTNL_DESTROY_CONTEXT(ctx);
+	ret = NETLINK_SEND_VALIDATE(ctx);
+	NETLINK_DESTROY_CONTEXT(ctx);
 
 	if (!ret) {
 		tst_brk(TBROK, "Failed to set ltp_veth1 address");
include/tst_rtnetlink.h +43 -42

143 lines not on this page · raw message

lib/tst_netdevice.c +47 -46

273 lines not on this page · raw message

lib/tst_rtnetlink.c +42 -41

230 lines not on this page · raw message

testcases/cve/tcindex01.c +1 -1
index 001056820..0fd254a92 100644
@@ -95,7 +95,7 @@ static void run(void)
 		1, "tcindex");
 	ret = tst_netdev_add_traffic_filter(__FILE__, __LINE__, 0, DEVNAME,
 		qd_handle, 10, ETH_P_IP, 1, "tcindex", f_config);
-	TST_ERR = tst_rtnl_errno;
+	TST_ERR = tst_netlink_errno;
 	NETDEV_REMOVE_QDISC(DEVNAME, AF_UNSPEC, TC_H_ROOT, qd_handle, "htb");
 
 	if (ret)
Signature · 5 lines
2.42.0


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

Re: [LTP] [PATCH v2 1/5] tst_rtnetlink: Refactor helper function for generic use

Hi Martin,

...

Quoted 3 lines

-3 rtnetlink API
+3 Netlink API
---------------

I fixed formatting (this must be shorter: ------------) and merged the first 3 commits.

Thanks!

Kind regards,
Petr

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

PATCH v2 2/5 tst_netlink_destroy_context(): Allow safely passing NULL context

In reply to Martin Doucha

---

Changes since v1: None

 lib/tst_rtnetlink.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tst_rtnetlink.c +3 -0
index eacfdced1..bf782ffb5 100644
@@ -55,6 +55,9 @@ static int netlink_grow_buffer(const char *file, const int lineno,
 void tst_netlink_destroy_context(const char *file, const int lineno,
 	struct tst_netlink_context *ctx)
 {
+	if (!ctx)
+		return;
+
 	safe_close(file, lineno, NULL, ctx->socket);
 	free(ctx->buffer);
 	free(ctx);
Signature · 5 lines
2.42.0


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

PATCH v2 3/5 crypto: Replace old netlink helper functions with netlink contexts

In reply to Martin Doucha

Finish refactoring of netlink helper functions for generic use and replace the very limited netlink send/receive functions used by the crypto tests with the new context-based helpers.

---

Changes since v1:
- Rebased
- Removed doc references to tst_crypto_session

The tst_netlink_context structure is initialized by NETLINK_CREATE_CONTEXT(), no macro is needed or even desirable since it's an opaque structure. It has no documentation so I've just removed the @relates references
to tst_crypto_session.

 doc/C-Test-Network-API.asciidoc         |   4 +-
 include/tst_crypto.h                    |  69 +---------
 include/tst_netdevice.h                 |   2 +-
 include/tst_netlink.h                   | 171 ++++++++++++++----------
 include/tst_rtnetlink.h                 | 109 ---------------
 lib/tst_crypto.c                        |  90 +++----------
 lib/tst_netdevice.c                     |   2 +-
 lib/{tst_rtnetlink.c => tst_netlink.c}  |   2 +-
 testcases/cve/tcindex01.c               |   2 +-
 testcases/kernel/crypto/crypto_user01.c |  58 +++-----
 testcases/kernel/crypto/crypto_user02.c |  17 +--
 testcases/kernel/crypto/pcrypt_aead01.c |  10 +-
 12 files changed, 159 insertions(+), 377 deletions(-)
 delete mode 100644 include/tst_rtnetlink.h
 rename lib/{tst_rtnetlink.c => tst_netlink.c} (99%)
doc/C-Test-Network-API.asciidoc +2 -2
index 25e4bbd18..d04dd6aa3 100644
@@ -277,7 +277,7 @@ static void setup(void)
 3 Netlink API
 ---------------
 
-+#include "tst_rtnetlink.h"+
++#include "tst_netlink.h"+
 
 The netlink library provides helper functions for constructing and sending
 arbitrary messages and parsing kernel responses.
@@ -443,7 +443,7 @@ Example Usage
 #include <arpa/inet.h>
 
 #include "tst_test.h"
-#include "tst_rtnetlink.h"
+#include "tst_netlink.h"
 #include "tst_netdevice.h"
 
 ...
include/tst_crypto.h +7 -62

96 lines not on this page · raw message

include/tst_netdevice.h +1 -1
index 5e62ba065..4239d0960 100644
@@ -5,7 +5,7 @@
 #ifndef TST_NETDEVICE_H
 #define TST_NETDEVICE_H
 
-#include "tst_rtnetlink.h"
+#include "tst_netlink.h"
 
 /* Find device index for given network interface name. */
 int tst_netdev_index_by_name(const char *file, const int lineno,
include/tst_netlink.h +97 -74

184 lines not on this page · raw message

include/tst_rtnetlink.h deleted +0 -109

109 lines not on this page · raw message

lib/tst_crypto.c +15 -75

117 lines not on this page · raw message

lib/tst_netdevice.c +1 -1
index 5873b3d58..6f86b8089 100644
@@ -12,7 +12,7 @@
 
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
-#include "tst_rtnetlink.h"
+#include "tst_netlink.h"
 #include "tst_netdevice.h"
 
 static struct tst_netlink_context *create_request(const char *file,
lib/tst_netlink.c renamed from lib/tst_rtnetlink.c +1 -1
similarity index 99%
rename from lib/tst_rtnetlink.c
rename to lib/tst_netlink.c
index bf782ffb5..bd05df81a 100644
@@ -13,7 +13,7 @@
 #include <sys/poll.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
-#include "tst_rtnetlink.h"
+#include "tst_netlink.h"
 
 struct tst_netlink_context {
 	int socket;
testcases/cve/tcindex01.c +1 -1
index 0fd254a92..d441a2449 100644
@@ -24,7 +24,7 @@
 #include <linux/pkt_sched.h>
 #include <linux/pkt_cls.h>
 #include "tst_test.h"
-#include "tst_rtnetlink.h"
+#include "tst_netlink.h"
 #include "tst_netdevice.h"
 #include "lapi/sched.h"
 #include "lapi/if_ether.h"
testcases/kernel/crypto/crypto_user01.c +20 -38

98 lines not on this page · raw message

testcases/kernel/crypto/crypto_user02.c +9 -8
index afaff5d18..89cbb9bc5 100644
@@ -52,7 +52,7 @@ static const char * const ALGORITHM_CANDIDATES[] = {
 };
 
 static const char* algorithm = NULL;
-static struct tst_crypto_session ses = TST_CRYPTO_SESSION_INIT;
+static struct tst_netlink_context *ctx;
 
 
 static void setup(void)
@@ -60,7 +60,8 @@ static void setup(void)
 	int rc;
 	unsigned i;
 	struct crypto_user_alg alg;
-	tst_crypto_open(&ses);
+
+	ctx = NETLINK_CREATE_CONTEXT(NETLINK_CRYPTO);
 
 	/* find an algorithm, that is not in use */
 	for (i = 0; i < ARRAY_SIZE(ALGORITHM_CANDIDATES); ++i) {
@@ -68,12 +69,12 @@ static void setup(void)
 		strcpy(alg.cru_driver_name, ALGORITHM_CANDIDATES[i]);
 
 		/* try to add it, to see if it is valid */
-		rc = tst_crypto_add_alg(&ses, &alg);
+		rc = tst_crypto_add_alg(ctx, &alg);
 		if (rc != 0)
 			continue;
 
 		/* it also has to be deletable */
-		rc = tst_crypto_del_alg(&ses, &alg);
+		rc = tst_crypto_del_alg(ctx, &alg, 1000);
 		if (rc == 0) {
 			algorithm = ALGORITHM_CANDIDATES[i];
 			break;
@@ -103,9 +104,9 @@ static void run(void)
 
 		if (pid == 0) {
 			/* Child process: execute CRYPTO_MSG_NEWALG. */
-			tst_crypto_open(&ses);
+			ctx = NETLINK_CREATE_CONTEXT(NETLINK_CRYPTO);
 			for (;;) {
-				TEST(tst_crypto_add_alg(&ses, &alg));
+				TEST(tst_crypto_add_alg(ctx, &alg));
 				if (TST_RET && TST_RET != -EEXIST)
 					tst_brk(TBROK | TRERRNO,
 						"unexpected error from tst_crypto_add_alg()");
@@ -123,7 +124,7 @@ static void run(void)
 		SAFE_WAIT(&status);
 		if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL)
 			tst_brk(TBROK, "child %s", tst_strstatus(status));
-		TEST(tst_crypto_del_alg(&ses, &alg));
+		TEST(tst_crypto_del_alg(ctx, &alg, 1000));
 		if (TST_RET && TST_RET != -ENOENT)
 			tst_brk(TBROK | TRERRNO,
 				"unexpected error from tst_crypto_del_alg()");
@@ -134,7 +135,7 @@ static void run(void)
 
 static void cleanup(void)
 {
-	tst_crypto_close(&ses);
+	NETLINK_DESTROY_CONTEXT(ctx);
 }
 
 static struct tst_test test = {
testcases/kernel/crypto/pcrypt_aead01.c +5 -5
index 3b4f5d8d1..3979f317a 100644
@@ -26,11 +26,11 @@
 
 #define ATTEMPTS 10000
 
-static struct tst_crypto_session ses = TST_CRYPTO_SESSION_INIT;
+static struct tst_netlink_context *ctx;
 
 void setup(void)
 {
-	tst_crypto_open(&ses);
+	ctx = NETLINK_CREATE_CONTEXT(NETLINK_CRYPTO);
 }
 
 void run(void)
@@ -43,7 +43,7 @@ void run(void)
 	};
 
 	for (i = 0; i < ATTEMPTS; ++i) {
-		TEST(tst_crypto_add_alg(&ses, &a));
+		TEST(tst_crypto_add_alg(ctx, &a));
 		if (TST_RET && TST_RET == -ENOENT) {
 			tst_brk(TCONF | TRERRNO,
 				"pcrypt, hmac, sha256, cbc or aes not supported");
@@ -51,7 +51,7 @@ void run(void)
 		if (TST_RET && TST_RET != -EEXIST)
 			tst_brk(TBROK | TRERRNO, "add_alg");
 
-		TEST(tst_crypto_del_alg(&ses, &a));
+		TEST(tst_crypto_del_alg(ctx, &a, 1000));
 		if (TST_RET)
 			tst_brk(TBROK | TRERRNO, "del_alg");
 
@@ -67,7 +67,7 @@ void run(void)
 
 void cleanup(void)
 {
-	tst_crypto_close(&ses);
+	NETLINK_DESTROY_CONTEXT(ctx);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.42.0


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

PATCH v2 4/5 tst_netlink: Add helper functions for handling generic attributes

In reply to Martin Doucha

Refactor struct tst_rtnl_attr_list for generic use and add helper functions for handling generic struct nlattr message attributes.

---

Changes since v1: New patch

 include/tst_netdevice.h   |  6 +--
 include/tst_netlink.h     | 38 ++++++++++++++----
 lib/tst_netdevice.c       | 20 +++++-----
 lib/tst_netlink.c         | 82 ++++++++++++++++++++++++++++++++++++++-
 testcases/cve/tcindex01.c | 12 +++---
 5 files changed, 131 insertions(+), 27 deletions(-)
include/tst_netdevice.h +3 -3
index 4239d0960..8d40148a6 100644
@@ -132,7 +132,7 @@ int tst_netdev_remove_route_inet(const char *file, const int lineno,
 int tst_netdev_add_qdisc(const char *file, const int lineno, int strict,
 	const char *ifname, unsigned int family, unsigned int parent,
 	unsigned int handle, const char *qd_kind,
-	const struct tst_rtnl_attr_list *config);
+	const struct tst_netlink_attr_list *config);
 #define NETDEV_ADD_QDISC(ifname, family, parent, handle, qd_kind, config) \
 	tst_netdev_add_qdisc(__FILE__, __LINE__, 1, (ifname), (family), \
 		(parent), (handle), (qd_kind), (config))
@@ -154,7 +154,7 @@ int tst_netdev_remove_qdisc(const char *file, const int lineno, int strict,
 int tst_netdev_add_traffic_class(const char *file, const int lineno,
 	int strict, const char *ifname, unsigned int parent,
 	unsigned int handle, const char *qd_kind,
-	const struct tst_rtnl_attr_list *config);
+	const struct tst_netlink_attr_list *config);
 #define NETDEV_ADD_TRAFFIC_CLASS(ifname, parent, handle, qd_kind, config) \
 	tst_netdev_add_traffic_class(__FILE__, __LINE__, 1, (ifname), \
 		(parent), (handle), (qd_kind), (config))
@@ -173,7 +173,7 @@ int tst_netdev_remove_traffic_class(const char *file, const int lineno,
 int tst_netdev_add_traffic_filter(const char *file, const int lineno,
 	int strict, const char *ifname, unsigned int parent,
 	unsigned int handle, unsigned int protocol, unsigned int priority,
-	const char *f_kind, const struct tst_rtnl_attr_list *config);
+	const char *f_kind, const struct tst_netlink_attr_list *config);
 #define NETDEV_ADD_TRAFFIC_FILTER(ifname, parent, handle, protocol, priority, \
 	f_kind, config) \
 	tst_netdev_add_traffic_filter(__FILE__, __LINE__, 1, (ifname), \
include/tst_netlink.h +31 -7
index f10f1cf5d..7d96fd711 100644
@@ -9,11 +9,11 @@
 
 struct tst_netlink_context;
 
-struct tst_rtnl_attr_list {
+struct tst_netlink_attr_list {
 	unsigned short type;
 	const void *data;
 	ssize_t len;
-	const struct tst_rtnl_attr_list *sublist;
+	const struct tst_netlink_attr_list *sublist;
 };
 
 struct tst_netlink_message {
@@ -72,25 +72,49 @@ int tst_netlink_add_message(const char *file, const int lineno,
 	tst_netlink_add_message(__FILE__, __LINE__, (ctx), (header), \
 		(payload), (psize))
 
-/* Add arbitrary attribute to last message */
+/* Add arbitrary nlattr attribute to last message */
+int tst_netlink_add_attr(const char *file, const int lineno,
+	struct tst_netlink_context *ctx, unsigned short type, const void *data,
+	unsigned short len);
+#define NETLINK_ADD_ATTR(ctx, type, data, len) \
+	tst_netlink_add_attr(__FILE__, __LINE__, (ctx), (type), (data), (len))
+
+/* Add string nlattr attribute to last message */
+int tst_netlink_add_attr_string(const char *file, const int lineno,
+	struct tst_netlink_context *ctx, unsigned short type, const char *data);
+#define NETLINK_ADD_ATTR_STRING(ctx, type, data) \
+	tst_netlink_add_attr_string(__FILE__, __LINE__, (ctx), (type), (data))
+
+/*
+ * Add list of arbitrary nlattr attributes to last message. The list is
+ * terminated by attribute with negative length. Nested sublists are supported.
+ */
+int tst_netlink_add_attr_list(const char *file, const int lineno,
+	struct tst_netlink_context *ctx,
+	const struct tst_netlink_attr_list *list);
+#define NETLINK_ADD_ATTR_LIST(ctx, list) \
+	tst_netlink_add_attr_list(__FILE__, __LINE__, (ctx), (list))
+
+/* Add arbitrary rtattr attribute to last message */
 int tst_rtnl_add_attr(const char *file, const int lineno,
 	struct tst_netlink_context *ctx, unsigned short type, const void *data,
 	unsigned short len);
 #define RTNL_ADD_ATTR(ctx, type, data, len) \
 	tst_rtnl_add_attr(__FILE__, __LINE__, (ctx), (type), (data), (len))
 
-/* Add string attribute to last message */
+/* Add string rtattr attribute to last message */
 int tst_rtnl_add_attr_string(const char *file, const int lineno,
 	struct tst_netlink_context *ctx, unsigned short type, const char *data);
 #define RTNL_ADD_ATTR_STRING(ctx, type, data) \
 	tst_rtnl_add_attr_string(__FILE__, __LINE__, (ctx), (type), (data))
 
 /*
- * Add list of arbitrary attributes to last message. The list is terminated
- * by attribute with negative length. Nested sublists are supported.
+ * Add list of arbitrary rtattr attributes to last message. The list is
+ * terminated by attribute with negative length. Nested sublists are supported.
  */
 int tst_rtnl_add_attr_list(const char *file, const int lineno,
-	struct tst_netlink_context *ctx, const struct tst_rtnl_attr_list *list);
+	struct tst_netlink_context *ctx,
+	const struct tst_netlink_attr_list *list);
 #define RTNL_ADD_ATTR_LIST(ctx, list) \
 	tst_rtnl_add_attr_list(__FILE__, __LINE__, (ctx), (list))
 
lib/tst_netdevice.c +10 -10
index 6f86b8089..1042466bf 100644
@@ -105,17 +105,17 @@ int tst_create_veth_pair(const char *file, const int lineno, int strict,
 	int ret;
 	struct ifinfomsg info = { .ifi_family = AF_UNSPEC };
 	struct tst_netlink_context *ctx;
-	struct tst_rtnl_attr_list peerinfo[] = {
+	struct tst_netlink_attr_list peerinfo[] = {
 		{IFLA_IFNAME, ifname2, strlen(ifname2) + 1, NULL},
 		{0, NULL, -1, NULL}
 	};
-	struct tst_rtnl_attr_list peerdata[] = {
+	struct tst_netlink_attr_list peerdata[] = {
 		{VETH_INFO_PEER, &info, sizeof(info), peerinfo},
 		{0, NULL, -1, NULL}
 	};
-	struct tst_rtnl_attr_list attrs[] = {
+	struct tst_netlink_attr_list attrs[] = {
 		{IFLA_IFNAME, ifname1, strlen(ifname1) + 1, NULL},
-		{IFLA_LINKINFO, NULL, 0, (const struct tst_rtnl_attr_list[]){
+		{IFLA_LINKINFO, NULL, 0, (const struct tst_netlink_attr_list[]){
 			{IFLA_INFO_KIND, "veth", 4, NULL},
 			{IFLA_INFO_DATA, NULL, 0, peerdata},
 			{0, NULL, -1, NULL}
@@ -164,9 +164,9 @@ int tst_netdev_add_device(const char *file, const int lineno, int strict,
 	int ret;
 	struct ifinfomsg info = { .ifi_family = AF_UNSPEC };
 	struct tst_netlink_context *ctx;
-	struct tst_rtnl_attr_list attrs[] = {
+	struct tst_netlink_attr_list attrs[] = {
 		{IFLA_IFNAME, ifname, strlen(ifname) + 1, NULL},
-		{IFLA_LINKINFO, NULL, 0, (const struct tst_rtnl_attr_list[]){
+		{IFLA_LINKINFO, NULL, 0, (const struct tst_netlink_attr_list[]){
 			{IFLA_INFO_KIND, devtype, strlen(devtype), NULL},
 			{0, NULL, -1, NULL}
 		}},
@@ -527,7 +527,7 @@ static int modify_qdisc(const char *file, const int lineno, int strict,
 	const char *object, unsigned int action, unsigned int nl_flags,
 	const char *ifname, unsigned int family, unsigned int parent,
 	unsigned int handle, unsigned int info, const char *qd_kind,
-	const struct tst_rtnl_attr_list *config)
+	const struct tst_netlink_attr_list *config)
 {
 	struct tst_netlink_context *ctx;
 	int ret;
@@ -585,7 +585,7 @@ static int modify_qdisc(const char *file, const int lineno, int strict,
 int tst_netdev_add_qdisc(const char *file, const int lineno, int strict,
 	const char *ifname, unsigned int family, unsigned int parent,
 	unsigned int handle, const char *qd_kind,
-	const struct tst_rtnl_attr_list *config)
+	const struct tst_netlink_attr_list *config)
 {
 	return modify_qdisc(file, lineno, strict, "queueing discipline",
 		RTM_NEWQDISC, NLM_F_CREATE | NLM_F_EXCL, ifname, family,
@@ -604,7 +604,7 @@ int tst_netdev_remove_qdisc(const char *file, const int lineno, int strict,
 int tst_netdev_add_traffic_class(const char *file, const int lineno,
 	int strict, const char *ifname, unsigned int parent,
 	unsigned int handle, const char *qd_kind,
-	const struct tst_rtnl_attr_list *config)
+	const struct tst_netlink_attr_list *config)
 {
 	return modify_qdisc(file, lineno, strict, "traffic class",
 		RTM_NEWTCLASS, NLM_F_CREATE | NLM_F_EXCL, ifname, AF_UNSPEC,
@@ -623,7 +623,7 @@ int tst_netdev_remove_traffic_class(const char *file, const int lineno,
 int tst_netdev_add_traffic_filter(const char *file, const int lineno,
 	int strict, const char *ifname, unsigned int parent,
 	unsigned int handle, unsigned int protocol, unsigned int priority,
-	const char *f_kind, const struct tst_rtnl_attr_list *config)
+	const char *f_kind, const struct tst_netlink_attr_list *config)
 {
 	return modify_qdisc(file, lineno, strict, "traffic filter",
 		RTM_NEWTFILTER, NLM_F_CREATE | NLM_F_EXCL, ifname, AF_UNSPEC,
lib/tst_netlink.c +81 -1

94 lines not on this page · raw message

testcases/cve/tcindex01.c +6 -6
index d441a2449..b4f2bb01a 100644
@@ -46,15 +46,15 @@ static const struct tc_htb_glob qd_opt = {
 static struct tc_htb_opt cls_opt = {};
 
 /* htb qdisc and class options */
-static const struct tst_rtnl_attr_list qd_config[] = {
-	{TCA_OPTIONS, NULL, 0, (const struct tst_rtnl_attr_list[]){
+static const struct tst_netlink_attr_list qd_config[] = {
+	{TCA_OPTIONS, NULL, 0, (const struct tst_netlink_attr_list[]){
 		{TCA_HTB_INIT, &qd_opt, sizeof(qd_opt), NULL},
 		{0, NULL, -1, NULL}
 	}},
 	{0, NULL, -1, NULL}
 };
-static const struct tst_rtnl_attr_list cls_config[] = {
-	{TCA_OPTIONS, NULL, 0, (const struct tst_rtnl_attr_list[]){
+static const struct tst_netlink_attr_list cls_config[] = {
+	{TCA_OPTIONS, NULL, 0, (const struct tst_netlink_attr_list[]){
 		{TCA_HTB_PARMS, &cls_opt, sizeof(cls_opt), NULL},
 		{0, NULL, -1, NULL}
 	}},
@@ -62,8 +62,8 @@ static const struct tst_rtnl_attr_list cls_config[] = {
 };
 
 /* tcindex filter options */
-static const struct tst_rtnl_attr_list f_config[] = {
-	{TCA_OPTIONS, NULL, 0, (const struct tst_rtnl_attr_list[]){
+static const struct tst_netlink_attr_list f_config[] = {
+	{TCA_OPTIONS, NULL, 0, (const struct tst_netlink_attr_list[]){
 		{TCA_TCINDEX_MASK, &mask, sizeof(mask), NULL},
 		{TCA_TCINDEX_SHIFT, &shift, sizeof(shift), NULL},
 		{TCA_TCINDEX_CLASSID, &clsid, sizeof(clsid), NULL},
Signature · 5 lines
2.42.0


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

PATCH v2 5/5 Add test for CVE 2023-31248

In reply to Martin Doucha

Fixes #1058

---

Changes since v1: New patch

 testcases/network/iptables/Makefile |   2 +-
 testcases/network/iptables/nft02.c  | 211 ++++++++++++++++++++++++++++
 2 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 testcases/network/iptables/nft02.c
testcases/network/iptables/Makefile +1 -1
index 1b42f25db..02e228cbc 100644
@@ -5,7 +5,7 @@
 
 top_srcdir		?= ../../..
 
-include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		:= *.sh
 
testcases/network/iptables/nft02.c new file +211 -0

211 lines not on this page · raw message

Signature · 5 lines
2.42.0


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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

testcases/network/iptables/nft02.c line 53

Quoted 5 lines
testcases/network/iptables/nft02.c new file +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+	{NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+	{NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+	{NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

Otherwise the patchset looks ok.

Kind regards,
Petr

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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

Hi Martin, Petr.

2023年11月15日(水) 0:39 Petr Vorel <[email protected]>:

Quoted 6 lines

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+     {NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+     {NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+     {NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

It was the same on RHEL8 (and/or other clone OS).

And, I would like to see this test added to runtest/cve and .gitignore.

Review

Quoted 4 lines
(quoted diff) +4 -0
+       if (tst_taint_check()) {
+               tst_res(TFAIL, "Kernel is vulnerable");
+               return;
+       }

Not a problem with the test itself but, If TAINT_W was already set, the test report TPASS by misstake.
Below patch masks TAINT_W if that taint flag was set before test started.

commit de9b5c2636204ab06dbb3c7dc57296d73ac572ac

Author: Jan Stancek <[email protected]>
Date:   Tue Apr 21 14:15:48 2020 +0200

lib: tst_taint: Ignore WARN taint flag if already set

This commit changes the library so that it ignores the taint warn flag if it was set prior to the test run. It turns out that the warn taint flag is not well defined and could be easily set on a freshly booted kernel for example when buggy BIOS is detected.

Other recent example is disabling ip forward on kvm guests:
https://github.com/containers/libpod/issues/5815
https://lore.kernel.org/netdev/[email protected]/

lib/tst_taint.c +7 -2
index a5dbf77d2..49146aacb 100644
@@ -82,9 +82,14 @@ void tst_taint_init(unsigned int mask)
                tst_res(TCONF, "Kernel is too old for requested mask");
 
        taint_mask = mask;
-
        taint = tst_taint_read();
-       if ((taint & mask) != 0)
+
+       if (taint & TST_TAINT_W) {
+               tst_res(TCONF, "Ignoring already set kernel warning taint");
+               taint_mask &= ~TST_TAINT_W;
+       }
+
+       if ((taint & taint_mask) != 0)
                tst_brk(TBROK, "Kernel is already tainted: %u", taint);
 }
 

Other tests rely on TAINT_W to decide the result also report TPASS by misstake if TAINT_W was already set.
In my patch v1 about CVE-2023-31248 check error == ENOENT. In this case, test reports correct result.
It may be difficult to implement test like patch v1 using the internal tst_netlink API, but we should be aware of this issue.

Best regards.
Souta Kawahara <[email protected]>

Quoted 8 lines

Otherwise the patchset looks ok.

Kind regards,
Petr

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

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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

Quoted 19 lines

Hi Martin, Petr.

2023年11月15日(水) 0:39 Petr Vorel <[email protected]>:

Quoted 5 lines

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+     {NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+     {NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+     {NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

Quoted 3 lines

It was the same on RHEL8 (and/or other clone OS).

And, I would like to see this test added to runtest/cve and .gitignore.

Good point, thanks. Maybe it could be also in runtest/net.tcp_cmds.

Quoted 50 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+       if (tst_taint_check()) {
+               tst_res(TFAIL, "Kernel is vulnerable");
+               return;
+       }

Not a problem with the test itself but, If TAINT_W was already set, the test report TPASS by misstake.
Below patch masks TAINT_W if that taint flag was set before test started.

commit de9b5c2636204ab06dbb3c7dc57296d73ac572ac

Author: Jan Stancek <[email protected]>
Date:   Tue Apr 21 14:15:48 2020 +0200

lib: tst_taint: Ignore WARN taint flag if already set

This commit changes the library so that it ignores the taint warn flag if it was set prior to the test run. It turns out that the warn taint flag is not well defined and could be easily set on a freshly booted kernel for example when buggy BIOS is detected.

Other recent example is disabling ip forward on kvm guests:
https://github.com/containers/libpod/issues/5815
https://lore.kernel.org/netdev/[email protected]/

lib/tst_taint.c +7 -2
index a5dbf77d2..49146aacb 100644
@@ -82,9 +82,14 @@ void tst_taint_init(unsigned int mask)
                tst_res(TCONF, "Kernel is too old for requested mask");
 
        taint_mask = mask;
-
        taint = tst_taint_read();
-       if ((taint & mask) != 0)
+
+       if (taint & TST_TAINT_W) {
+               tst_res(TCONF, "Ignoring already set kernel warning taint");
+               taint_mask &= ~TST_TAINT_W;
+       }
+
+       if ((taint & taint_mask) != 0)
                tst_brk(TBROK, "Kernel is already tainted: %u", taint);
 }
 
Quoted 6 lines

Other tests rely on TAINT_W to decide the result also report TPASS by misstake if TAINT_W was already set.
In my patch v1 about CVE-2023-31248 check error == ENOENT. In this case, test reports correct result.
It may be difficult to implement test like patch v1 using the internal tst_netlink API, but we should be aware of this issue.

Cc Jan. But if I read it correctly if the kernel is already tainted with TAINT_W, this flag is indeed skipped, but it can still be detected via TST_TAINT_D (oops).

Kind regards,
Petr

Quoted 12 lines

Best regards.
Souta Kawahara <[email protected]>

Quoted 7 lines

Otherwise the patchset looks ok.

Kind regards,
Petr

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

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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

Quoted 83 lines · Petr Vorel
Quoted 20 lines

Hi Martin, Petr.

2023年11月15日(水) 0:39 Petr Vorel <[email protected]>:

Quoted 5 lines

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+     {NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+     {NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+     {NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

Quoted 3 lines

It was the same on RHEL8 (and/or other clone OS).

And, I would like to see this test added to runtest/cve and .gitignore.

Good point, thanks. Maybe it could be also in runtest/net.tcp_cmds.

Quoted 50 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+       if (tst_taint_check()) {
+               tst_res(TFAIL, "Kernel is vulnerable");
+               return;
+       }

Not a problem with the test itself but, If TAINT_W was already set, the test report TPASS by misstake.
Below patch masks TAINT_W if that taint flag was set before test started.

commit de9b5c2636204ab06dbb3c7dc57296d73ac572ac

Author: Jan Stancek <[email protected]>
Date:   Tue Apr 21 14:15:48 2020 +0200

lib: tst_taint: Ignore WARN taint flag if already set

This commit changes the library so that it ignores the taint warn flag if it was set prior to the test run. It turns out that the warn taint flag is not well defined and could be easily set on a freshly booted kernel for example when buggy BIOS is detected.

Other recent example is disabling ip forward on kvm guests:
https://github.com/containers/libpod/issues/5815
https://lore.kernel.org/netdev/[email protected]/

lib/tst_taint.c +7 -2
index a5dbf77d2..49146aacb 100644
@@ -82,9 +82,14 @@ void tst_taint_init(unsigned int mask)
                tst_res(TCONF, "Kernel is too old for requested mask");
 
        taint_mask = mask;
-
        taint = tst_taint_read();
-       if ((taint & mask) != 0)
+
+       if (taint & TST_TAINT_W) {
+               tst_res(TCONF, "Ignoring already set kernel warning taint");
+               taint_mask &= ~TST_TAINT_W;
+       }
+
+       if ((taint & taint_mask) != 0)
                tst_brk(TBROK, "Kernel is already tainted: %u", taint);
 }
 
Quoted 6 lines

Other tests rely on TAINT_W to decide the result also report TPASS by misstake if TAINT_W was already set.
In my patch v1 about CVE-2023-31248 check error == ENOENT. In this case, test reports correct result.
It may be difficult to implement test like patch v1 using the internal tst_netlink API, but we should be aware of this issue.

Quoted 3 lines

Cc Jan. But if I read it correctly if the kernel is already tainted with TAINT_W, this flag is indeed skipped, but it can still be detected via TST_TAINT_D (oops).

If we mask already set TAINT_W, you can get PASS by mistake, if we don't mask it, you can get FAIL by mistake - which one is better?

I believe at the time we saw masking as better alternative, since many CI systems also look at dmesg/journal and would find WARNING messages even when test reports PASS by mistake. So the failure wouldn't go unnoticed.

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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

In reply to 河原颯太

Hi,

Quoted 19 lines · 河原颯太

Hi Martin, Petr.

2023年11月15日(水) 0:39 Petr Vorel <[email protected]>:

Quoted 6 lines

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+     {NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+     {NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+     {NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

Quoted 3 lines

It was the same on RHEL8 (and/or other clone OS).

And, I would like to see this test added to runtest/cve and .gitignore.

Yes, sorry, I realized that shortly after submission and will fix it in the next version.

Quoted 4 lines

In my patch v1 about CVE-2023-31248 check error == ENOENT. In this case, test reports correct result.
It may be difficult to implement test like patch v1 using the internal tst_netlink API, but we should be aware of this issue.

I've rewritten the test to use ENOENT check with the tst_netlink API. May I credit you with Co-Developed-by or Suggested-by (choose one)?

Signature · 11 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


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

Re: [LTP] [PATCH v2 5/5] Add test for CVE 2023-31248

Hi Martin,

2023年11月16日(木) 2:34 Martin Doucha <[email protected]>:

Quoted 30 lines

Hi,

Quoted 19 lines · 河原颯太

Hi Martin, Petr.

2023年11月15日(水) 0:39 Petr Vorel <[email protected]>:

Quoted 6 lines

Hi Martin,

...

Quoted 1 line

+++ b/testcases/network/iptables/nft02.c

...

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Chain creation and deletion config */
+static const struct tst_netlink_attr_list newchain_config[] = {
+     {NFTA_TABLE_NAME, TABNAME, strlen(TABNAME) + 1, NULL},
+     {NFTA_CHAIN_NAME, CHAINNAME, strlen(CHAINNAME) + 1, NULL},
+     {NFTA_CHAIN_ID, &chain_id, sizeof(chain_id), NULL},

Unfortunately the current oldest distros (Leap 42 and Ubuntu Bionic) are too old for NFTA_CHAIN_ID, NFTA_RULE_CHAIN_ID, could you please add them to LAPI?

Quoted 3 lines

It was the same on RHEL8 (and/or other clone OS).

And, I would like to see this test added to runtest/cve and .gitignore.

Yes, sorry, I realized that shortly after submission and will fix it in the next version.

Quoted 7 lines
Quoted 4 lines

In my patch v1 about CVE-2023-31248 check error == ENOENT. In this case, test reports correct result.
It may be difficult to implement test like patch v1 using the internal tst_netlink API, but we should be aware of this issue.

I've rewritten the test to use ENOENT check with the tst_netlink API. May I credit you with Co-Developed-by or Suggested-by (choose one)?

Good! Thank You so much.
Co-Developed-by is better for me :)

Best regards,
Souta Kawahara <[email protected]>

Quoted 10 lines

--
Martin Doucha [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

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