Skip to contentSkip to conversation

netfilter: nf_log: consolidate check for NULL logger in lookup function

PATCH New Pablo Neira Ayuso 1 participant 2 messages Jan 29, 2024

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: nf_log: consolidate check for NULL logger in lookup function

Consolidate pointer fetch to logger and check for NULL in __find_logger().

---
 net/netfilter/nf_log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_log.c +2 -2
index e16f158388bb..e0bfeb75766f 100644
@@ -31,10 +31,10 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
 	int i;
 
 	for (i = 0; i < NF_LOG_TYPE_MAX; i++) {
-		if (loggers[pf][i] == NULL)
+		log = nft_log_dereference(loggers[pf][i]);
+		if (!log)
 			continue;
 
-		log = nft_log_dereference(loggers[pf][i]);
 		if (!strncasecmp(str_logger, log->name, strlen(log->name)))
 			return log;
 	}
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/2 netfilter: nf_log: validate nf_logger_find_get()

Sanitize nf_logger_find_get() input parameters, no caller in the tree passes invalid values.

---
 net/netfilter/nf_log.c | 5 +++++
 1 file changed, 5 insertions(+)
net/netfilter/nf_log.c +5 -0
index e0bfeb75766f..370f8231385c 100644
@@ -156,6 +156,11 @@ int nf_logger_find_get(int pf, enum nf_log_type type)
 	struct nf_logger *logger;
 	int ret = -ENOENT;
 
+	if (pf >= ARRAY_SIZE(loggers))
+		return -EINVAL;
+	if (type >= NF_LOG_TYPE_MAX)
+		return -EINVAL;
+
 	if (pf == NFPROTO_INET) {
 		ret = nf_logger_find_get(NFPROTO_IPV4, type);
 		if (ret < 0)
Signature · 1 line
2.30.2