Skip to content

Commit f01e1af

Browse files
committed
selinux: don't pass in NULL avd to avc_has_perm_noaudit
Right now security_get_user_sids() will pass in a NULL avd pointer to avc_has_perm_noaudit(), which then forces that function to have a dummy entry for that case and just generally test it. Don't do it. The normal callers all pass a real avd pointer, and this helper function is incredibly hot. So don't make avc_has_perm_noaudit() do conditional stuff that isn't needed for the common case. This also avoids some duplicated stack space. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bc9bc72 commit f01e1af

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

‎security/selinux/avc.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,9 @@ int avc_ss_reset(u32 seqno)
752752
int avc_has_perm_noaudit(u32 ssid, u32 tsid,
753753
u16 tclass, u32 requested,
754754
unsigned flags,
755-
struct av_decision *in_avd)
755+
struct av_decision *avd)
756756
{
757757
struct avc_node *node;
758-
struct av_decision avd_entry, *avd;
759758
int rc = 0;
760759
u32 denied;
761760

@@ -766,18 +765,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
766765
node = avc_lookup(ssid, tsid, tclass);
767766
if (unlikely(!node)) {
768767
rcu_read_unlock();
769-
770-
if (in_avd)
771-
avd = in_avd;
772-
else
773-
avd = &avd_entry;
774-
775768
security_compute_av(ssid, tsid, tclass, avd);
776769
rcu_read_lock();
777770
node = avc_insert(ssid, tsid, tclass, avd);
778771
} else {
779-
if (in_avd)
780-
memcpy(in_avd, &node->ae.avd, sizeof(*in_avd));
772+
memcpy(avd, &node->ae.avd, sizeof(*avd));
781773
avd = &node->ae.avd;
782774
}
783775

‎security/selinux/ss/services.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,10 +2217,11 @@ int security_get_user_sids(u32 fromsid,
22172217
goto out;
22182218
}
22192219
for (i = 0, j = 0; i < mynel; i++) {
2220+
struct av_decision dummy_avd;
22202221
rc = avc_has_perm_noaudit(fromsid, mysids[i],
22212222
SECCLASS_PROCESS, /* kernel value */
22222223
PROCESS__TRANSITION, AVC_STRICT,
2223-
NULL);
2224+
&dummy_avd);
22242225
if (!rc)
22252226
mysids2[j++] = mysids[i];
22262227
cond_resched();

0 commit comments

Comments
 (0)