mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selinux: use int arrays for boolean values
@ 2022-08-30 15:45 Christian Göttsche
  2022-08-30 21:04 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Göttsche @ 2022-08-30 15:45 UTC (permalink / raw)
  To: selinux; +Cc: Paul Moore, Stephen Smalley, Eric Paris, linux-kernel

Do not cast pointers of signed integers to pointers of unsigned integers
and vice versa.

It should currently not be an issue since they hold SELinux boolean
values which should only contain either 0's or 1's, which should have
the same representation.

Reported by sparse:

    security/selinux/selinuxfs.c:1485:30: warning: incorrect type in assignment (different signedness)
    security/selinux/selinuxfs.c:1485:30:    expected unsigned int *
    security/selinux/selinuxfs.c:1485:30:    got int *[addressable] values
    security/selinux/selinuxfs.c:1402:48: warning: incorrect type in argument 3 (different signedness)
    security/selinux/selinuxfs.c:1402:48:    expected int *values
    security/selinux/selinuxfs.c:1402:48:    got unsigned int *bool_pending_values

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
Previous patch proposal: https://patchwork.kernel.org/project/selinux/patch/20220502135907.31035-1-cgzones@googlemail.com/
---
 security/selinux/selinuxfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 8fcdd494af27..f0b1aafd67aa 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -71,7 +71,7 @@ struct selinux_fs_info {
 	struct dentry *bool_dir;
 	unsigned int bool_num;
 	char **bool_pending_names;
-	unsigned int *bool_pending_values;
+	int *bool_pending_values;
 	struct dentry *class_dir;
 	unsigned long last_class_ino;
 	bool policy_opened;
@@ -356,7 +356,7 @@ static const struct file_operations sel_policyvers_ops = {
 /* declaration for sel_write_load */
 static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
 			  unsigned int *bool_num, char ***bool_pending_names,
-			  unsigned int **bool_pending_values);
+			  int **bool_pending_values);
 static int sel_make_classes(struct selinux_policy *newpolicy,
 			    struct dentry *class_dir,
 			    unsigned long *last_class_ino);
@@ -527,7 +527,7 @@ static const struct file_operations sel_policy_ops = {
 };
 
 static void sel_remove_old_bool_data(unsigned int bool_num, char **bool_names,
-				unsigned int *bool_values)
+				int *bool_values)
 {
 	u32 i;
 
@@ -545,7 +545,7 @@ static int sel_make_policy_nodes(struct selinux_fs_info *fsi,
 	struct dentry *tmp_parent, *tmp_bool_dir, *tmp_class_dir, *old_dentry;
 	unsigned int tmp_bool_num, old_bool_num;
 	char **tmp_bool_names, **old_bool_names;
-	unsigned int *tmp_bool_values, *old_bool_values;
+	int *tmp_bool_values, *old_bool_values;
 	unsigned long tmp_ino = fsi->last_ino; /* Don't increment last_ino in this function */
 
 	tmp_parent = sel_make_disconnected_dir(fsi->sb, &tmp_ino);
@@ -1423,7 +1423,7 @@ static void sel_remove_entries(struct dentry *de)
 
 static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
 			  unsigned int *bool_num, char ***bool_pending_names,
-			  unsigned int **bool_pending_values)
+			  int **bool_pending_values)
 {
 	int ret;
 	ssize_t len;
-- 
2.37.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selinux: use int arrays for boolean values
  2022-08-30 15:45 [PATCH] selinux: use int arrays for boolean values Christian Göttsche
@ 2022-08-30 21:04 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2022-08-30 21:04 UTC (permalink / raw)
  To: Christian Göttsche
  Cc: selinux, Stephen Smalley, Eric Paris, linux-kernel

On Tue, Aug 30, 2022 at 11:45 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> Do not cast pointers of signed integers to pointers of unsigned integers
> and vice versa.
>
> It should currently not be an issue since they hold SELinux boolean
> values which should only contain either 0's or 1's, which should have
> the same representation.
>
> Reported by sparse:
>
>     security/selinux/selinuxfs.c:1485:30: warning: incorrect type in assignment (different signedness)
>     security/selinux/selinuxfs.c:1485:30:    expected unsigned int *
>     security/selinux/selinuxfs.c:1485:30:    got int *[addressable] values
>     security/selinux/selinuxfs.c:1402:48: warning: incorrect type in argument 3 (different signedness)
>     security/selinux/selinuxfs.c:1402:48:    expected int *values
>     security/selinux/selinuxfs.c:1402:48:    got unsigned int *bool_pending_values
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> Previous patch proposal: https://patchwork.kernel.org/project/selinux/patch/20220502135907.31035-1-cgzones@googlemail.com/
> ---
>  security/selinux/selinuxfs.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Merged into selinux/next, thanks!

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-30 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 15:45 [PATCH] selinux: use int arrays for boolean values Christian Göttsche
2022-08-30 21:04 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®