From 40f3011a6b52d6cace6f4084dc014813c802779e Mon Sep 17 00:00:00 2001 From: Yousha Aleayoub Date: Thu, 29 Feb 2024 13:09:10 +0330 Subject: [PATCH] Improve selnl_msglen() function. --- security/selinux/netlink.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/security/selinux/netlink.c b/security/selinux/netlink.c index 1760aee712fd..d0e853fa80ba 100644 --- a/security/selinux/netlink.c +++ b/security/selinux/netlink.c @@ -23,21 +23,23 @@ static struct sock *selnl __ro_after_init; static int selnl_msglen(int msgtype) { - int ret = 0; + int ret = 0; - switch (msgtype) { - case SELNL_MSG_SETENFORCE: - ret = sizeof(struct selnl_msg_setenforce); - break; + switch (msgtype) { + case SELNL_MSG_SETENFORCE: + ret = sizeof(struct selnl_msg_setenforce); + break; - case SELNL_MSG_POLICYLOAD: - ret = sizeof(struct selnl_msg_policyload); - break; + case SELNL_MSG_POLICYLOAD: + ret = sizeof(struct selnl_msg_policyload); + break; - default: - BUG(); - } - return ret; + default: + pr_err("Unknown message type in selnl_msglen: %d\n", msgtype); + ret = -EINVAL; // Return an error code or appropriate default value + } + + return ret; } static void selnl_add_payload(struct nlmsghdr *nlh, int len, int msgtype, void *data)