From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [RFC PATCH v2 4/9] libselinux: add unique id to sidtab entries
Date: Wed, 31 Jan 2024 14:08:30 +0100 [thread overview]
Message-ID: <20240131130840.48155-5-cgzones@googlemail.com> (raw)
In-Reply-To: <20240131130840.48155-1-cgzones@googlemail.com>
Reinterpret the currently unused - and always initialized to 1 - member
refcnt of the struct security_id to hold a unique number identifying
the sidtab entry. This identifier can be used instead of the full
context string within other data structures to minimize memory usage.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
v2:
add patch
---
libselinux/include/selinux/avc.h | 2 +-
libselinux/src/avc_sidtab.c | 9 +++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/libselinux/include/selinux/avc.h b/libselinux/include/selinux/avc.h
index 4bbd2382..361c5611 100644
--- a/libselinux/include/selinux/avc.h
+++ b/libselinux/include/selinux/avc.h
@@ -20,7 +20,7 @@ extern "C" {
*/
struct security_id {
char * ctx;
- unsigned int refcnt;
+ unsigned int id;
};
typedef struct security_id *security_id_t;
diff --git a/libselinux/src/avc_sidtab.c b/libselinux/src/avc_sidtab.c
index fce5bddf..9475dcb0 100644
--- a/libselinux/src/avc_sidtab.c
+++ b/libselinux/src/avc_sidtab.c
@@ -4,6 +4,7 @@
* Author : Eamon Walsh, <ewalsh@epoch.ncsc.mil>
*/
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -50,6 +51,11 @@ int sidtab_insert(struct sidtab *s, const char * ctx)
struct sidtab_node *newnode;
char * newctx;
+ if (s->nel >= UINT_MAX - 1) {
+ rc = -1;
+ goto out;
+ }
+
newnode = (struct sidtab_node *)avc_malloc(sizeof(*newnode));
if (!newnode) {
rc = -1;
@@ -65,9 +71,8 @@ int sidtab_insert(struct sidtab *s, const char * ctx)
hvalue = sidtab_hash(newctx);
newnode->next = s->htable[hvalue];
newnode->sid_s.ctx = newctx;
- newnode->sid_s.refcnt = 1; /* unused */
+ newnode->sid_s.id = ++s->nel;
s->htable[hvalue] = newnode;
- s->nel++;
out:
return rc;
}
--
2.43.0
next prev parent reply other threads:[~2024-01-31 13:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 13:08 [RFC PATCH v2 0/9] libselinux: rework selabel_file(5) database Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 1/9] policycoreutils: introduce unsetfiles Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 2/9] libselinux/utils: introduce selabel_compare Christian Göttsche
2024-03-07 19:50 ` James Carter
2024-03-11 17:20 ` Christian Göttsche
2024-03-11 20:49 ` James Carter
2024-01-31 13:08 ` [RFC PATCH v2 3/9] libselinux: use more appropriate types in sidtab Christian Göttsche
2024-01-31 13:08 ` Christian Göttsche [this message]
2024-01-31 13:08 ` [RFC PATCH v2 5/9] libselinux: sidtab updates Christian Göttsche
2024-03-07 20:53 ` James Carter
2024-03-11 16:32 ` Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 6/9] libselinux: rework selabel_file(5) database Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 7/9] libselinux: remove unused hashtab code Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 8/9] libselinux: add selabel_file(5) fuzzer Christian Göttsche
2024-01-31 13:08 ` [RFC PATCH v2 9/9] libselinux: support parallel selabel_lookup(3) Christian Göttsche
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=20240131130840.48155-5-cgzones@googlemail.com \
--to=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