Skip to content

Commit 03ca0ec

Browse files
thomas-cedenomicah-morton
authored andcommitted
LSM: SafeSetID: Fix warnings reported by test bot
Fix multiple cast-to-union warnings related to casting kuid_t and kgid_t types to kid_t union type. Also fix incompatible type warning that arises from accidental omission of "__rcu" qualifier on the struct setid_ruleset pointer in the argument list for safesetid_file_read(). Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Thomas Cedeno <thomascedeno@google.com> Signed-off-by: Micah Morton <mortonm@chromium.org>
1 parent 5294bac commit 03ca0ec

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

security/safesetid/lsm.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int safesetid_security_capable(const struct cred *cred,
116116
* If no policy applies to this task, allow the use of CAP_SETUID for
117117
* other purposes.
118118
*/
119-
if (setid_policy_lookup((kid_t)cred->uid, INVALID_ID, UID) == SIDPOL_DEFAULT)
119+
if (setid_policy_lookup((kid_t){.uid = cred->uid}, INVALID_ID, UID) == SIDPOL_DEFAULT)
120120
return 0;
121121
/*
122122
* Reject use of CAP_SETUID for functionality other than calling
@@ -131,7 +131,7 @@ static int safesetid_security_capable(const struct cred *cred,
131131
* If no policy applies to this task, allow the use of CAP_SETGID for
132132
* other purposes.
133133
*/
134-
if (setid_policy_lookup((kid_t)cred->gid, INVALID_ID, GID) == SIDPOL_DEFAULT)
134+
if (setid_policy_lookup((kid_t){.gid = cred->gid}, INVALID_ID, GID) == SIDPOL_DEFAULT)
135135
return 0;
136136
/*
137137
* Reject use of CAP_SETUID for functionality other than calling
@@ -174,7 +174,7 @@ static bool id_permitted_for_cred(const struct cred *old, kid_t new_id, enum set
174174
* RUID.
175175
*/
176176
permitted =
177-
setid_policy_lookup((kid_t)old->uid, new_id, new_type) != SIDPOL_CONSTRAINED;
177+
setid_policy_lookup((kid_t){.uid = old->uid}, new_id, new_type) != SIDPOL_CONSTRAINED;
178178

179179
if (!permitted) {
180180
if (new_type == UID) {
@@ -202,13 +202,13 @@ static int safesetid_task_fix_setuid(struct cred *new,
202202
{
203203

204204
/* Do nothing if there are no setuid restrictions for our old RUID. */
205-
if (setid_policy_lookup((kid_t)old->uid, INVALID_ID, UID) == SIDPOL_DEFAULT)
205+
if (setid_policy_lookup((kid_t){.uid = old->uid}, INVALID_ID, UID) == SIDPOL_DEFAULT)
206206
return 0;
207207

208-
if (id_permitted_for_cred(old, (kid_t)new->uid, UID) &&
209-
id_permitted_for_cred(old, (kid_t)new->euid, UID) &&
210-
id_permitted_for_cred(old, (kid_t)new->suid, UID) &&
211-
id_permitted_for_cred(old, (kid_t)new->fsuid, UID))
208+
if (id_permitted_for_cred(old, (kid_t){.uid = new->uid}, UID) &&
209+
id_permitted_for_cred(old, (kid_t){.uid = new->euid}, UID) &&
210+
id_permitted_for_cred(old, (kid_t){.uid = new->suid}, UID) &&
211+
id_permitted_for_cred(old, (kid_t){.uid = new->fsuid}, UID))
212212
return 0;
213213

214214
/*
@@ -226,13 +226,13 @@ static int safesetid_task_fix_setgid(struct cred *new,
226226
{
227227

228228
/* Do nothing if there are no setgid restrictions for our old RGID. */
229-
if (setid_policy_lookup((kid_t)old->gid, INVALID_ID, GID) == SIDPOL_DEFAULT)
229+
if (setid_policy_lookup((kid_t){.gid = old->gid}, INVALID_ID, GID) == SIDPOL_DEFAULT)
230230
return 0;
231231

232-
if (id_permitted_for_cred(old, (kid_t)new->gid, GID) &&
233-
id_permitted_for_cred(old, (kid_t)new->egid, GID) &&
234-
id_permitted_for_cred(old, (kid_t)new->sgid, GID) &&
235-
id_permitted_for_cred(old, (kid_t)new->fsgid, GID))
232+
if (id_permitted_for_cred(old, (kid_t){.gid = new->gid}, GID) &&
233+
id_permitted_for_cred(old, (kid_t){.gid = new->egid}, GID) &&
234+
id_permitted_for_cred(old, (kid_t){.gid = new->sgid}, GID) &&
235+
id_permitted_for_cred(old, (kid_t){.gid = new->fsgid}, GID))
236236
return 0;
237237

238238
/*

security/safesetid/securityfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static ssize_t safesetid_gid_file_write(struct file *file,
261261
}
262262

263263
static ssize_t safesetid_file_read(struct file *file, char __user *buf,
264-
size_t len, loff_t *ppos, struct mutex *policy_update_lock, struct setid_ruleset* ruleset)
264+
size_t len, loff_t *ppos, struct mutex *policy_update_lock, struct __rcu setid_ruleset* ruleset)
265265
{
266266
ssize_t res = 0;
267267
struct setid_ruleset *pol;

0 commit comments

Comments
 (0)