History

conntrack: export lsm context rather than internal secid via netlink

The conntrack code can export the internal secid to userspace. These are dynamic, can change on lsm changes, and have no meaning in userspace. We should instead be sending lsm contexts to userspace instead. This patch sends the secctx (rather than secid) to userspace over the netlink socket. We use a new field CTA_SECCTX and stop using the the old CTA_SECMARK field since it did not send particularly useful information.

Eric Paris committed 16 years ago

Commit 1cc63241 parent d5630b92 files · +45 −11Browse files

Unified · Split

2 files
  1. include/linux/netfilter/nfnetlink_conntrack.h +9 −1
  2. net/netfilter/nf_conntrack_netlink.c +36 −10
include/linux/netfilter/nfnetlink_conntrack.h+9−1
@@ -39,8 +39,9 @@ enum ctattr_type { · 38 unmodified lines
3939 CTA_TUPLE_MASTER,
4040 CTA_NAT_SEQ_ADJ_ORIG,
4141 CTA_NAT_SEQ_ADJ_REPLY,
42− CTA_SECMARK,
42+ CTA_SECMARK, /* obsolete */
4343 CTA_ZONE,
44+ CTA_SECCTX,
4445 __CTA_MAX
4546 };
4647 #define CTA_MAX (__CTA_MAX - 1)
@@ -172,4 +173,11 @@ enum ctattr_help { · 125 unmodified lines
172173 };
173174 #define CTA_HELP_MAX (__CTA_HELP_MAX - 1)
174175
176+enum ctattr_secctx {
177+ CTA_SECCTX_UNSPEC,
178+ CTA_SECCTX_NAME,
179+ __CTA_SECCTX_MAX
180+};
181+#define CTA_SECCTX_MAX (__CTA_SECCTX_MAX - 1)
182+
175183 #endif /* _IPCONNTRACK_NETLINK_H */
net/netfilter/nf_conntrack_netlink.c+36−10
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <linux/rculist_nulls.h>
2323 #include <linux/types.h>
2424 #include <linux/timer.h>
25+#include <linux/security.h>
2526 #include <linux/skbuff.h>
2627 #include <linux/errno.h>
2728 #include <linux/netlink.h>
@@ -245,16 +246,31 @@ nla_put_failure: · 217 unmodified lines
245246
246247 #ifdef CONFIG_NF_CONNTRACK_SECMARK
247248 static inline int
248−ctnetlink_dump_secmark(struct sk_buff *skb, const struct nf_conn *ct)
249+ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
249250 {
250− NLA_PUT_BE32(skb, CTA_SECMARK, htonl(ct->secmark));
251− return 0;
251+ struct nlattr *nest_secctx;
252+ int len, ret;
253+ char *secctx;
254+
255+ ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
256+ if (ret)
257+ return ret;
258+
259+ ret = -1;
260+ nest_secctx = nla_nest_start(skb, CTA_SECCTX | NLA_F_NESTED);
261+ if (!nest_secctx)
262+ goto nla_put_failure;
252263
264+ NLA_PUT_STRING(skb, CTA_SECCTX_NAME, secctx);
265+ nla_nest_end(skb, nest_secctx);
266+
267+ ret = 0;
253268 nla_put_failure:
254− return -1;
269+ security_release_secctx(secctx, len);
270+ return ret;
255271 }
256272 #else
257−#define ctnetlink_dump_secmark(a, b) (0)
273+#define ctnetlink_dump_secctx(a, b) (0)
258274 #endif
259275
260276 #define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
@@ -391,7 +407,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, · 130 unmodified lines
391407 ctnetlink_dump_protoinfo(skb, ct) < 0 ||
392408 ctnetlink_dump_helpinfo(skb, ct) < 0 ||
393409 ctnetlink_dump_mark(skb, ct) < 0 ||
394− ctnetlink_dump_secmark(skb, ct) < 0 ||
410+ ctnetlink_dump_secctx(skb, ct) < 0 ||
395411 ctnetlink_dump_id(skb, ct) < 0 ||
396412 ctnetlink_dump_use(skb, ct) < 0 ||
397413 ctnetlink_dump_master(skb, ct) < 0 ||
@@ -437,6 +453,17 @@ ctnetlink_counters_size(const struct nf_conn *ct) · 39 unmodified lines
437453 ;
438454 }
439455
456+#ifdef CONFIG_NF_CONNTRACK_SECMARK
457+static int ctnetlink_nlmsg_secctx_size(const struct nf_conn *ct)
458+{
459+ int len;
460+
461+ security_secid_to_secctx(ct->secmark, NULL, &len);
462+
463+ return sizeof(char) * len;
464+}
465+#endif
466+
440467 static inline size_t
441468 ctnetlink_nlmsg_size(const struct nf_conn *ct)
442469 {
@@ -453,7 +480,8 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct) · 10 unmodified lines
453480 + nla_total_size(0) /* CTA_HELP */
454481 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
455482 #ifdef CONFIG_NF_CONNTRACK_SECMARK
456− + nla_total_size(sizeof(u_int32_t)) /* CTA_SECMARK */
483+ + nla_total_size(0) /* CTA_SECCTX */
484+ + nla_total_size(ctnetlink_nlmsg_secctx_size(ct)) /* CTA_SECCTX_NAME */
457485 #endif
458486 #ifdef CONFIG_NF_NAT_NEEDED
459487 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
@@ -554,11 +582,9 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) · 94 unmodified lines
554582 && ctnetlink_dump_helpinfo(skb, ct) < 0)
555583 goto nla_put_failure;
556584
557−#ifdef CONFIG_NF_CONNTRACK_SECMARK
558585 if ((events & (1 << IPCT_SECMARK) || ct->secmark)
559− && ctnetlink_dump_secmark(skb, ct) < 0)
586+ && ctnetlink_dump_secctx(skb, ct) < 0)
560587 goto nla_put_failure;
561−#endif
562588
563589 if (events & (1 << IPCT_RELATED) &&
564590 ctnetlink_dump_master(skb, ct) < 0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t