Skip to content

Commit 3b44cd0

Browse files
cschauflerpcmoore
authored andcommitted
net: corrections for security_secid_to_secctx returns
security_secid_to_secctx() returns the size of the new context, whereas previous versions provided that via a pointer parameter. Correct the type of the value returned in nfqnl_get_sk_secctx() and the check for error in netlbl_unlhsh_add(). Add an error check. Fixes: 2d470c7 ("lsm: replace context+len with lsm_context") Signed-off-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent b00083a commit 3b44cd0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

net/netfilter/nfnetlink_queue.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ static int nfqnl_put_sk_classid(struct sk_buff *skb, struct sock *sk)
470470
return 0;
471471
}
472472

473-
static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, struct lsm_context *ctx)
473+
static int nfqnl_get_sk_secctx(struct sk_buff *skb, struct lsm_context *ctx)
474474
{
475-
u32 seclen = 0;
475+
int seclen = 0;
476476
#if IS_ENABLED(CONFIG_NETWORK_SECMARK)
477477

478478
if (!skb || !sk_fullsock(skb->sk))
@@ -568,7 +568,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
568568
const struct nfnl_ct_hook *nfnl_ct;
569569
bool csum_verify;
570570
struct lsm_context ctx;
571-
u32 seclen = 0;
571+
int seclen = 0;
572572
ktime_t tstamp;
573573

574574
size = nlmsg_total_size(sizeof(struct nfgenmsg))
@@ -643,7 +643,9 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
643643

644644
if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) {
645645
seclen = nfqnl_get_sk_secctx(entskb, &ctx);
646-
if (seclen >= 0)
646+
if (seclen < 0)
647+
return NULL;
648+
if (seclen)
647649
size += nla_total_size(seclen);
648650
}
649651

@@ -782,7 +784,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
782784
if (nfqnl_put_sk_classid(skb, entskb->sk) < 0)
783785
goto nla_put_failure;
784786

785-
if (seclen && nla_put(skb, NFQA_SECCTX, ctx.len, ctx.context))
787+
if (seclen > 0 && nla_put(skb, NFQA_SECCTX, ctx.len, ctx.context))
786788
goto nla_put_failure;
787789

788790
if (ct && nfnl_ct->build(skb, ct, ctinfo, NFQA_CT, NFQA_CT_INFO) < 0)

net/netlabel/netlabel_unlabeled.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ int netlbl_unlhsh_add(struct net *net,
437437
unlhsh_add_return:
438438
rcu_read_unlock();
439439
if (audit_buf != NULL) {
440-
if (security_secid_to_secctx(secid, &ctx) == 0) {
440+
if (security_secid_to_secctx(secid, &ctx) >= 0) {
441441
audit_log_format(audit_buf, " sec_obj=%s", ctx.context);
442442
security_release_secctx(&ctx);
443443
}
@@ -490,7 +490,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net,
490490
addr->s_addr, mask->s_addr);
491491
dev_put(dev);
492492
if (entry != NULL &&
493-
security_secid_to_secctx(entry->secid, &ctx) == 0) {
493+
security_secid_to_secctx(entry->secid, &ctx) >= 0) {
494494
audit_log_format(audit_buf, " sec_obj=%s", ctx.context);
495495
security_release_secctx(&ctx);
496496
}
@@ -548,7 +548,7 @@ static int netlbl_unlhsh_remove_addr6(struct net *net,
548548
addr, mask);
549549
dev_put(dev);
550550
if (entry != NULL &&
551-
security_secid_to_secctx(entry->secid, &ctx) == 0) {
551+
security_secid_to_secctx(entry->secid, &ctx) >= 0) {
552552
audit_log_format(audit_buf, " sec_obj=%s", ctx.context);
553553
security_release_secctx(&ctx);
554554
}

0 commit comments

Comments
 (0)