Skip to content

Commit ef5f46b

Browse files
committed
Merge tag 'selinux-pr-20260501' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux fixes from Paul Moore: - Ensure SELinux is always properly accessing its own sock LSM state - Only reserve an xattr slot for SELinux if it will be used - Fix a SELinux auditing regression in the directory avdcache * tag 'selinux-pr-20260501' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: fix avdcache auditing selinux: don't reserve xattr slot when we won't fill it selinux: use sk blob accessor in socket permission helpers
2 parents ee9dce4 + f92d542 commit ef5f46b

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

security/selinux/hooks.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
29662966
{
29672967
const struct cred_security_struct *crsec = selinux_cred(current_cred());
29682968
struct superblock_security_struct *sbsec;
2969-
struct xattr *xattr = lsm_get_xattr_slot(xattrs, xattr_count);
2969+
struct xattr *xattr;
29702970
u32 newsid, clen;
29712971
u16 newsclass;
29722972
int rc;
@@ -2992,6 +2992,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
29922992
!(sbsec->flags & SBLABEL_MNT))
29932993
return -EOPNOTSUPP;
29942994

2995+
xattr = lsm_get_xattr_slot(xattrs, xattr_count);
29952996
if (xattr) {
29962997
rc = security_sid_to_context_force(newsid,
29972998
&context, &clen);
@@ -3208,15 +3209,13 @@ static inline int task_avdcache_search(struct task_security_struct *tsec,
32083209
* @tsec: the task's security state
32093210
* @isec: the inode associated with the cache entry
32103211
* @avd: the AVD to cache
3211-
* @audited: the permission audit bitmask to cache
32123212
*
3213-
* Update the AVD cache in @tsec with the @avdc and @audited info associated
3213+
* Update the AVD cache in @tsec with the @avd info associated
32143214
* with @isec.
32153215
*/
32163216
static inline void task_avdcache_update(struct task_security_struct *tsec,
32173217
struct inode_security_struct *isec,
3218-
struct av_decision *avd,
3219-
u32 audited)
3218+
struct av_decision *avd)
32203219
{
32213220
int spot;
32223221

@@ -3228,9 +3227,7 @@ static inline void task_avdcache_update(struct task_security_struct *tsec,
32283227
spot = (tsec->avdcache.dir_spot + 1) & (TSEC_AVDC_DIR_SIZE - 1);
32293228
tsec->avdcache.dir_spot = spot;
32303229
tsec->avdcache.dir[spot].isid = isec->sid;
3231-
tsec->avdcache.dir[spot].audited = audited;
3232-
tsec->avdcache.dir[spot].allowed = avd->allowed;
3233-
tsec->avdcache.dir[spot].permissive = avd->flags & AVD_FLAGS_PERMISSIVE;
3230+
tsec->avdcache.dir[spot].avd = *avd;
32343231
tsec->avdcache.permissive_neveraudit =
32353232
(avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
32363233
}
@@ -3251,6 +3248,7 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32513248
struct task_security_struct *tsec;
32523249
struct inode_security_struct *isec;
32533250
struct avdc_entry *avdc;
3251+
struct av_decision avd, *avdp = &avd;
32543252
int rc, rc2;
32553253
u32 audited, denied;
32563254

@@ -3272,23 +3270,21 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32723270
rc = task_avdcache_search(tsec, isec, &avdc);
32733271
if (likely(!rc)) {
32743272
/* Cache hit. */
3275-
audited = perms & avdc->audited;
3276-
denied = perms & ~avdc->allowed;
3277-
if (unlikely(denied && enforcing_enabled() &&
3278-
!avdc->permissive))
3273+
avdp = &avdc->avd;
3274+
denied = perms & ~avdp->allowed;
3275+
if (unlikely(denied) && enforcing_enabled() &&
3276+
!(avdp->flags & AVD_FLAGS_PERMISSIVE))
32793277
rc = -EACCES;
32803278
} else {
3281-
struct av_decision avd;
3282-
32833279
/* Cache miss. */
32843280
rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3285-
perms, 0, &avd);
3286-
audited = avc_audit_required(perms, &avd, rc,
3287-
(requested & MAY_ACCESS) ? FILE__AUDIT_ACCESS : 0,
3288-
&denied);
3289-
task_avdcache_update(tsec, isec, &avd, audited);
3281+
perms, 0, avdp);
3282+
task_avdcache_update(tsec, isec, avdp);
32903283
}
32913284

3285+
audited = avc_audit_required(perms, avdp, rc,
3286+
(requested & MAY_ACCESS) ?
3287+
FILE__AUDIT_ACCESS : 0, &denied);
32923288
if (likely(!audited))
32933289
return rc;
32943290

@@ -4920,7 +4916,7 @@ static bool sock_skip_has_perm(u32 sid)
49204916

49214917
static int sock_has_perm(struct sock *sk, u32 perms)
49224918
{
4923-
struct sk_security_struct *sksec = sk->sk_security;
4919+
struct sk_security_struct *sksec = selinux_sock(sk);
49244920
struct common_audit_data ad;
49254921
struct lsm_network_audit net;
49264922

@@ -6227,7 +6223,7 @@ static unsigned int selinux_ip_postroute(void *priv,
62276223

62286224
static int nlmsg_sock_has_extended_perms(struct sock *sk, u32 perms, u16 nlmsg_type)
62296225
{
6230-
struct sk_security_struct *sksec = sk->sk_security;
6226+
struct sk_security_struct *sksec = selinux_sock(sk);
62316227
struct common_audit_data ad;
62326228
u8 driver;
62336229
u8 xperm;

security/selinux/include/objsec.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232

3333
struct avdc_entry {
3434
u32 isid; /* inode SID */
35-
u32 allowed; /* allowed permission bitmask */
36-
u32 audited; /* audited permission bitmask */
37-
bool permissive; /* AVC permissive flag */
35+
struct av_decision avd; /* av decision */
3836
};
3937

4038
struct cred_security_struct {

0 commit comments

Comments
 (0)