From: Johannes Segitz <jsegitz@suse.de>
To: "Christian Göttsche" <cgzones@googlemail.com>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH] libselinux: Cached security context not accurate
Date: Mon, 24 Jan 2022 09:51:13 +0100 [thread overview]
Message-ID: <20220124085113.GC5813@suse.com> (raw)
In-Reply-To: <CAJ2a_Ded5vUji+FmPZ0F09aZ_QGzk_aSAVKiejbAkwJNcPfEDg@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 749 bytes --]
On Fri, Jan 21, 2022 at 01:06:16PM +0100, Christian Göttsche wrote:
> Wouldn't it make logically more sense to first check if pid is zero
> and then check if the cache is set, cause we never want to access the
> cache if not operating on out own process?
Yes, I changed that
> Also isn't setprocattrcon_raw() affected too?
Of course. I managed to attach the wrong file that only had the change for
getprocattrcon_raw. Attached is the full patch
Johannes
--
GPG Key EE16 6BCE AD56 E034 BFB3 3ADD 7BF7 29D5 E7C8 1FA0
Subkey fingerprint: 250F 43F5 F7CE 6F1E 9C59 4F95 BC27 DD9D 2CC4 FD66
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nuernberg
Geschäftsführer: Ivo Totev (HRB 36809, AG Nürnberg)
[-- Attachment #1.2: libselinux_procattr_cache.patch --]
[-- Type: text/x-patch, Size: 1124 bytes --]
Index: libselinux-3.3/src/procattr.c
===================================================================
--- libselinux-3.3.orig/src/procattr.c
+++ libselinux-3.3/src/procattr.c
@@ -148,7 +148,7 @@ static int getprocattrcon_raw(char ** co
return -1;
}
- if (prev_context && prev_context != UNSET) {
+ if (pid == 0 && prev_context && prev_context != UNSET) {
*context = strdup(prev_context);
if (!(*context)) {
return -1;
@@ -242,9 +242,9 @@ static int setprocattrcon_raw(const char
return -1;
}
- if (!context && !*prev_context)
+ if (pid == 0 && !context && !*prev_context)
return 0;
- if (context && *prev_context && *prev_context != UNSET
+ if (pid == 0 && context && *prev_context && *prev_context != UNSET
&& !strcmp(context, *prev_context))
return 0;
@@ -272,9 +272,11 @@ out:
free(context2);
return -1;
} else {
- if (*prev_context != UNSET)
- free(*prev_context);
- *prev_context = context2;
+ if (pid == 0) {
+ if (*prev_context != UNSET)
+ free(*prev_context);
+ *prev_context = context2;
+ }
return 0;
}
}
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-01-24 8:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-21 8:40 [PATCH] libselinux: Cached security context not accurate Johannes Segitz
2022-01-21 12:06 ` Christian Göttsche
2022-01-24 8:51 ` Johannes Segitz [this message]
2022-01-25 15:06 ` Petr Lautrbach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220124085113.GC5813@suse.com \
--to=jsegitz@suse.de \
--cc=cgzones@googlemail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox