Patch "samples/landlock: Fix incorrect free in populate_ruleset_net" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    samples/landlock: Fix incorrect free in populate_ruleset_net

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     samples-landlock-fix-incorrect-free-in-populate_rule.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 85f5d01f7a8be9654f5324fb656018230cb2dd87
Author: Ivanov Mikhail <ivanov.mikhail1@xxxxxxxxxxxxxxxxxxx>
Date:   Tue Mar 26 17:56:25 2024 +0800

    samples/landlock: Fix incorrect free in populate_ruleset_net
    
    [ Upstream commit 42212936d9d811c7cf6efc4804747a6c417aafd4 ]
    
    Pointer env_port_name changes after strsep(). Memory allocated via
    strdup() will not be freed if landlock_add_rule() returns non-zero value.
    
    Fixes: 5e990dcef12e ("samples/landlock: Support TCP restrictions")
    Signed-off-by: Ivanov Mikhail <ivanov.mikhail1@xxxxxxxxxxxxxxxxxxx>
    Reviewed-by: Konstantin Meskhidze <konstantin.meskhidze@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240326095625.3576164-1-ivanov.mikhail1@xxxxxxxxxxxxxxxxxxx
    Signed-off-by: Mickaël Salaün <mic@xxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c
index 08596c0ef0707..e6c59f688573a 100644
--- a/samples/landlock/sandboxer.c
+++ b/samples/landlock/sandboxer.c
@@ -151,7 +151,7 @@ static int populate_ruleset_net(const char *const env_var, const int ruleset_fd,
 				const __u64 allowed_access)
 {
 	int ret = 1;
-	char *env_port_name, *strport;
+	char *env_port_name, *env_port_name_next, *strport;
 	struct landlock_net_port_attr net_port = {
 		.allowed_access = allowed_access,
 		.port = 0,
@@ -163,7 +163,8 @@ static int populate_ruleset_net(const char *const env_var, const int ruleset_fd,
 	env_port_name = strdup(env_port_name);
 	unsetenv(env_var);
 
-	while ((strport = strsep(&env_port_name, ENV_DELIMITER))) {
+	env_port_name_next = env_port_name;
+	while ((strport = strsep(&env_port_name_next, ENV_DELIMITER))) {
 		net_port.port = atoi(strport);
 		if (landlock_add_rule(ruleset_fd, LANDLOCK_RULE_NET_PORT,
 				      &net_port, 0)) {




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux