Skip to content

Commit 2e71029

Browse files
Tetsuo Handaklassert
authored andcommitted
xfrm: Remove useless xfrm_audit struct.
Commit f1370cc "xfrm: Remove useless secid field from xfrm_audit." changed "struct xfrm_audit" to have either { audit_get_loginuid(current) / audit_get_sessionid(current) } or { INVALID_UID / -1 } pair. This means that we can represent "struct xfrm_audit" as "bool". This patch replaces "struct xfrm_audit" argument with "bool". Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent f1370cc commit 2e71029

5 files changed

Lines changed: 60 additions & 124 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,6 @@ struct xfrm_spi_skb_cb {
691691

692692
#define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0]))
693693

694-
/* Audit Information */
695-
struct xfrm_audit {
696-
kuid_t loginuid;
697-
unsigned int sessionid;
698-
};
699-
700694
#ifdef CONFIG_AUDITSYSCALL
701695
static inline struct audit_buffer *xfrm_audit_start(const char *op)
702696
{
@@ -712,22 +706,24 @@ static inline struct audit_buffer *xfrm_audit_start(const char *op)
712706
return audit_buf;
713707
}
714708

715-
static inline void xfrm_audit_helper_usrinfo(kuid_t auid, unsigned int ses,
709+
static inline void xfrm_audit_helper_usrinfo(bool task_valid,
716710
struct audit_buffer *audit_buf)
717711
{
718-
audit_log_format(audit_buf, " auid=%u ses=%u",
719-
from_kuid(&init_user_ns, auid), ses);
712+
const unsigned int auid = from_kuid(&init_user_ns, task_valid ?
713+
audit_get_loginuid(current) :
714+
INVALID_UID);
715+
const unsigned int ses = task_valid ? audit_get_sessionid(current) :
716+
(unsigned int) -1;
717+
718+
audit_log_format(audit_buf, " auid=%u ses=%u", auid, ses);
720719
audit_log_task_context(audit_buf);
721720
}
722721

723-
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, kuid_t auid,
724-
unsigned int ses);
725-
void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result, kuid_t auid,
726-
unsigned int ses);
727-
void xfrm_audit_state_add(struct xfrm_state *x, int result, kuid_t auid,
728-
unsigned int ses);
729-
void xfrm_audit_state_delete(struct xfrm_state *x, int result, kuid_t auid,
730-
unsigned int ses);
722+
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, bool task_valid);
723+
void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
724+
bool task_valid);
725+
void xfrm_audit_state_add(struct xfrm_state *x, int result, bool task_valid);
726+
void xfrm_audit_state_delete(struct xfrm_state *x, int result, bool task_valid);
731727
void xfrm_audit_state_replay_overflow(struct xfrm_state *x,
732728
struct sk_buff *skb);
733729
void xfrm_audit_state_replay(struct xfrm_state *x, struct sk_buff *skb,
@@ -740,22 +736,22 @@ void xfrm_audit_state_icvfail(struct xfrm_state *x, struct sk_buff *skb,
740736
#else
741737

742738
static inline void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
743-
kuid_t auid, unsigned int ses)
739+
bool task_valid)
744740
{
745741
}
746742

747743
static inline void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
748-
kuid_t auid, unsigned int ses)
744+
bool task_valid)
749745
{
750746
}
751747

752748
static inline void xfrm_audit_state_add(struct xfrm_state *x, int result,
753-
kuid_t auid, unsigned int ses)
749+
bool task_valid)
754750
{
755751
}
756752

757753
static inline void xfrm_audit_state_delete(struct xfrm_state *x, int result,
758-
kuid_t auid, unsigned int ses)
754+
bool task_valid)
759755
{
760756
}
761757

@@ -1499,7 +1495,7 @@ struct xfrmk_spdinfo {
14991495

15001496
struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq);
15011497
int xfrm_state_delete(struct xfrm_state *x);
1502-
int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info);
1498+
int xfrm_state_flush(struct net *net, u8 proto, bool task_valid);
15031499
void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si);
15041500
void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
15051501
u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);
@@ -1594,7 +1590,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark,
15941590
int *err);
15951591
struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir,
15961592
u32 id, int delete, int *err);
1597-
int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info);
1593+
int xfrm_policy_flush(struct net *net, u8 type, bool task_valid);
15981594
u32 xfrm_get_acqseq(void);
15991595
int verify_spi_info(u8 proto, u32 min, u32 max);
16001596
int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);

‎net/key/af_key.c‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,7 @@ static int pfkey_add(struct sock *sk, struct sk_buff *skb, const struct sadb_msg
14761476
else
14771477
err = xfrm_state_update(x);
14781478

1479-
xfrm_audit_state_add(x, err ? 0 : 1,
1480-
audit_get_loginuid(current),
1481-
audit_get_sessionid(current));
1479+
xfrm_audit_state_add(x, err ? 0 : 1, true);
14821480

14831481
if (err < 0) {
14841482
x->km.state = XFRM_STATE_DEAD;
@@ -1532,9 +1530,7 @@ static int pfkey_delete(struct sock *sk, struct sk_buff *skb, const struct sadb_
15321530
c.event = XFRM_MSG_DELSA;
15331531
km_state_notify(x, &c);
15341532
out:
1535-
xfrm_audit_state_delete(x, err ? 0 : 1,
1536-
audit_get_loginuid(current),
1537-
audit_get_sessionid(current));
1533+
xfrm_audit_state_delete(x, err ? 0 : 1, true);
15381534
xfrm_state_put(x);
15391535

15401536
return err;
@@ -1726,16 +1722,13 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, const struct sadb_m
17261722
struct net *net = sock_net(sk);
17271723
unsigned int proto;
17281724
struct km_event c;
1729-
struct xfrm_audit audit_info;
17301725
int err, err2;
17311726

17321727
proto = pfkey_satype2proto(hdr->sadb_msg_satype);
17331728
if (proto == 0)
17341729
return -EINVAL;
17351730

1736-
audit_info.loginuid = audit_get_loginuid(current);
1737-
audit_info.sessionid = audit_get_sessionid(current);
1738-
err = xfrm_state_flush(net, proto, &audit_info);
1731+
err = xfrm_state_flush(net, proto, true);
17391732
err2 = unicast_flush_resp(sk, hdr);
17401733
if (err || err2) {
17411734
if (err == -ESRCH) /* empty table - go quietly */
@@ -2287,9 +2280,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, const struct sadb_
22872280
err = xfrm_policy_insert(pol->sadb_x_policy_dir-1, xp,
22882281
hdr->sadb_msg_type != SADB_X_SPDUPDATE);
22892282

2290-
xfrm_audit_policy_add(xp, err ? 0 : 1,
2291-
audit_get_loginuid(current),
2292-
audit_get_sessionid(current));
2283+
xfrm_audit_policy_add(xp, err ? 0 : 1, true);
22932284

22942285
if (err)
22952286
goto out;
@@ -2371,9 +2362,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, const struct sa
23712362
if (xp == NULL)
23722363
return -ENOENT;
23732364

2374-
xfrm_audit_policy_delete(xp, err ? 0 : 1,
2375-
audit_get_loginuid(current),
2376-
audit_get_sessionid(current));
2365+
xfrm_audit_policy_delete(xp, err ? 0 : 1, true);
23772366

23782367
if (err)
23792368
goto out;
@@ -2621,9 +2610,7 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, const struct sadb_
26212610
return -ENOENT;
26222611

26232612
if (delete) {
2624-
xfrm_audit_policy_delete(xp, err ? 0 : 1,
2625-
audit_get_loginuid(current),
2626-
audit_get_sessionid(current));
2613+
xfrm_audit_policy_delete(xp, err ? 0 : 1, true);
26272614

26282615
if (err)
26292616
goto out;
@@ -2732,12 +2719,9 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, const struct sad
27322719
{
27332720
struct net *net = sock_net(sk);
27342721
struct km_event c;
2735-
struct xfrm_audit audit_info;
27362722
int err, err2;
27372723

2738-
audit_info.loginuid = audit_get_loginuid(current);
2739-
audit_info.sessionid = audit_get_sessionid(current);
2740-
err = xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
2724+
err = xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, true);
27412725
err2 = unicast_flush_resp(sk, hdr);
27422726
if (err || err2) {
27432727
if (err == -ESRCH) /* empty table - old silent behavior */

‎net/xfrm/xfrm_policy.c‎

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ EXPORT_SYMBOL(xfrm_policy_byid);
769769

770770
#ifdef CONFIG_SECURITY_NETWORK_XFRM
771771
static inline int
772-
xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audit_info)
772+
xfrm_policy_flush_secctx_check(struct net *net, u8 type, bool task_valid)
773773
{
774774
int dir, err = 0;
775775

@@ -783,9 +783,7 @@ xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audi
783783
continue;
784784
err = security_xfrm_policy_delete(pol->security);
785785
if (err) {
786-
xfrm_audit_policy_delete(pol, 0,
787-
audit_info->loginuid,
788-
audit_info->sessionid);
786+
xfrm_audit_policy_delete(pol, 0, task_valid);
789787
return err;
790788
}
791789
}
@@ -799,8 +797,7 @@ xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audi
799797
pol->security);
800798
if (err) {
801799
xfrm_audit_policy_delete(pol, 0,
802-
audit_info->loginuid,
803-
audit_info->sessionid);
800+
task_valid);
804801
return err;
805802
}
806803
}
@@ -810,19 +807,19 @@ xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audi
810807
}
811808
#else
812809
static inline int
813-
xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audit_info)
810+
xfrm_policy_flush_secctx_check(struct net *net, u8 type, bool task_valid)
814811
{
815812
return 0;
816813
}
817814
#endif
818815

819-
int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
816+
int xfrm_policy_flush(struct net *net, u8 type, bool task_valid)
820817
{
821818
int dir, err = 0, cnt = 0;
822819

823820
write_lock_bh(&net->xfrm.xfrm_policy_lock);
824821

825-
err = xfrm_policy_flush_secctx_check(net, type, audit_info);
822+
err = xfrm_policy_flush_secctx_check(net, type, task_valid);
826823
if (err)
827824
goto out;
828825

@@ -839,8 +836,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
839836
write_unlock_bh(&net->xfrm.xfrm_policy_lock);
840837
cnt++;
841838

842-
xfrm_audit_policy_delete(pol, 1, audit_info->loginuid,
843-
audit_info->sessionid);
839+
xfrm_audit_policy_delete(pol, 1, task_valid);
844840

845841
xfrm_policy_kill(pol);
846842

@@ -859,9 +855,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
859855
write_unlock_bh(&net->xfrm.xfrm_policy_lock);
860856
cnt++;
861857

862-
xfrm_audit_policy_delete(pol, 1,
863-
audit_info->loginuid,
864-
audit_info->sessionid);
858+
xfrm_audit_policy_delete(pol, 1, task_valid);
865859
xfrm_policy_kill(pol);
866860

867861
write_lock_bh(&net->xfrm.xfrm_policy_lock);
@@ -2858,19 +2852,14 @@ static int __net_init xfrm_policy_init(struct net *net)
28582852

28592853
static void xfrm_policy_fini(struct net *net)
28602854
{
2861-
struct xfrm_audit audit_info;
28622855
unsigned int sz;
28632856
int dir;
28642857

28652858
flush_work(&net->xfrm.policy_hash_work);
28662859
#ifdef CONFIG_XFRM_SUB_POLICY
2867-
audit_info.loginuid = INVALID_UID;
2868-
audit_info.sessionid = (unsigned int)-1;
2869-
xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, &audit_info);
2860+
xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, false);
28702861
#endif
2871-
audit_info.loginuid = INVALID_UID;
2872-
audit_info.sessionid = (unsigned int)-1;
2873-
xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
2862+
xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, false);
28742863

28752864
WARN_ON(!list_empty(&net->xfrm.policy_all));
28762865

@@ -2985,30 +2974,29 @@ static void xfrm_audit_common_policyinfo(struct xfrm_policy *xp,
29852974
}
29862975
}
29872976

2988-
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
2989-
kuid_t auid, unsigned int sessionid)
2977+
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, bool task_valid)
29902978
{
29912979
struct audit_buffer *audit_buf;
29922980

29932981
audit_buf = xfrm_audit_start("SPD-add");
29942982
if (audit_buf == NULL)
29952983
return;
2996-
xfrm_audit_helper_usrinfo(auid, sessionid, audit_buf);
2984+
xfrm_audit_helper_usrinfo(task_valid, audit_buf);
29972985
audit_log_format(audit_buf, " res=%u", result);
29982986
xfrm_audit_common_policyinfo(xp, audit_buf);
29992987
audit_log_end(audit_buf);
30002988
}
30012989
EXPORT_SYMBOL_GPL(xfrm_audit_policy_add);
30022990

30032991
void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
3004-
kuid_t auid, unsigned int sessionid)
2992+
bool task_valid)
30052993
{
30062994
struct audit_buffer *audit_buf;
30072995

30082996
audit_buf = xfrm_audit_start("SPD-delete");
30092997
if (audit_buf == NULL)
30102998
return;
3011-
xfrm_audit_helper_usrinfo(auid, sessionid, audit_buf);
2999+
xfrm_audit_helper_usrinfo(task_valid, audit_buf);
30123000
audit_log_format(audit_buf, " res=%u", result);
30133001
xfrm_audit_common_policyinfo(xp, audit_buf);
30143002
audit_log_end(audit_buf);

0 commit comments

Comments
 (0)