2023-07-06 13:26:15

by Christian Göttsche

[permalink] [raw]
Subject: [RFC PATCH 20/20] selinux: selinuxfs: avoid implicit conversions

Use unsigned loop counters where the upper bound is of unsigned
type.

Signed-off-by: Christian Göttsche <[email protected]>
---
security/selinux/selinuxfs.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 88d856f5c6bc..a2dc415779ae 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1074,7 +1074,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
u32 sid, *sids = NULL;
ssize_t length;
char *newcon;
- int i, rc;
+ int rc;
u32 len, nsids;

length = avc_has_perm(current_sid(), SECINITSID_SECURITY,
@@ -1107,7 +1107,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)

length = sprintf(buf, "%u", nsids) + 1;
ptr = buf + length;
- for (i = 0; i < nsids; i++) {
+ for (u32 i = 0; i < nsids; i++) {
rc = security_sid_to_context(sids[i], &newcon, &len);
if (rc) {
length = rc;
@@ -1612,7 +1612,6 @@ static int sel_make_avc_files(struct dentry *dir)
{
struct super_block *sb = dir->d_sb;
struct selinux_fs_info *fsi = sb->s_fs_info;
- int i;
static const struct tree_descr files[] = {
{ "cache_threshold",
&sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR },
@@ -1622,7 +1621,7 @@ static int sel_make_avc_files(struct dentry *dir)
#endif
};

- for (i = 0; i < ARRAY_SIZE(files); i++) {
+ for (u32 i = 0; i < ARRAY_SIZE(files); i++) {
struct inode *inode;
struct dentry *dentry;

@@ -1648,12 +1647,11 @@ static int sel_make_ss_files(struct dentry *dir)
{
struct super_block *sb = dir->d_sb;
struct selinux_fs_info *fsi = sb->s_fs_info;
- int i;
static const struct tree_descr files[] = {
{ "sidtab_hash_stats", &sel_sidtab_hash_stats_ops, S_IRUGO },
};

- for (i = 0; i < ARRAY_SIZE(files); i++) {
+ for (u32 i = 0; i < ARRAY_SIZE(files); i++) {
struct inode *inode;
struct dentry *dentry;

@@ -1699,9 +1697,7 @@ static const struct file_operations sel_initcon_ops = {

static int sel_make_initcon_files(struct dentry *dir)
{
- int i;
-
- for (i = 1; i <= SECINITSID_NUM; i++) {
+ for (u32 i = 1; i <= SECINITSID_NUM; i++) {
struct inode *inode;
struct dentry *dentry;
const char *s = security_get_initial_sid_context(i);
--
2.40.1



2023-07-18 22:04:47

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH RFC 20/20] selinux: selinuxfs: avoid implicit conversions

On Jul 6, 2023 =?UTF-8?q?Christian=20G=C3=B6ttsche?= <[email protected]> wrote:
>
> Use unsigned loop counters where the upper bound is of unsigned
> type.
>
> Signed-off-by: Christian Göttsche <[email protected]>
> ---
> security/selinux/selinuxfs.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)

More loop iterator declarations inside the loop, see my previous
comments.

--
paul-moore.com