From e08f099d027596e2c2e6124511e9db3359633147 Mon Sep 17 00:00:00 2001 From: YOSHIFUJI Hideaki Date: Thu, 10 Apr 2008 15:41:26 +0900 Subject: [PATCH] --- yaml --- r: 90627 b: refs/heads/master c: aba6096b21e151bc55da74605fe77b92cfcccb12 h: refs/heads/master i: 90625: 143012deb38773953a196edde6351da851c26610 90623: f004633da80074e02db9f6a0ac6dd7900b2d3774 v: v3 --- [refs] | 2 +- trunk/MAINTAINERS | 2 +- trunk/include/linux/security.h | 48 +++++++++++------------ trunk/include/net/netlabel.h | 14 ++----- trunk/net/ipv6/ip6_input.c | 26 ++++++------- trunk/net/key/af_key.c | 23 +++++------ trunk/net/sctp/associola.c | 34 +++++++++------- trunk/net/sctp/bind_addr.c | 15 +++++-- trunk/net/sctp/outqueue.c | 49 +++++++++++++++-------- trunk/net/sctp/proc.c | 23 ++++++----- trunk/net/sctp/sm_make_chunk.c | 10 +++-- trunk/net/sctp/sm_sideeffect.c | 23 +++++++---- trunk/net/sctp/sm_statefuns.c | 10 +++-- trunk/net/sctp/socket.c | 56 +++++++++++++++++++-------- trunk/net/unix/af_unix.c | 6 +-- trunk/net/xfrm/xfrm_policy.c | 24 +++++------- trunk/net/xfrm/xfrm_user.c | 33 ++++++++-------- trunk/security/dummy.c | 14 +++---- trunk/security/security.c | 21 +++++----- trunk/security/selinux/include/xfrm.h | 13 +++---- trunk/security/selinux/ss/services.c | 2 +- trunk/security/selinux/xfrm.c | 39 +++++++++++-------- trunk/security/smack/smack_lsm.c | 2 +- 23 files changed, 272 insertions(+), 217 deletions(-) diff --git a/[refs] b/[refs] index eca02d12f13b..aa18069d9345 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 03e1ad7b5d871d4189b1da3125c2f12d1b5f7d0b +refs/heads/master: aba6096b21e151bc55da74605fe77b92cfcccb12 diff --git a/trunk/MAINTAINERS b/trunk/MAINTAINERS index 802d88b3611c..c6ade7e777f3 100644 --- a/trunk/MAINTAINERS +++ b/trunk/MAINTAINERS @@ -3455,7 +3455,7 @@ P: Vlad Yasevich M: vladislav.yasevich@hp.com P: Sridhar Samudrala M: sri@us.ibm.com -L: linux-sctp@vger.kernel.org +L: lksctp-developers@lists.sourceforge.net W: http://lksctp.sourceforge.net S: Supported diff --git a/trunk/include/linux/security.h b/trunk/include/linux/security.h index f5eb9ff47ac5..c673dfd4dffc 100644 --- a/trunk/include/linux/security.h +++ b/trunk/include/linux/security.h @@ -910,24 +910,24 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) * Security hooks for XFRM operations. * * @xfrm_policy_alloc_security: - * @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy - * Database used by the XFRM system. + * @xp contains the xfrm_policy being added to Security Policy Database + * used by the XFRM system. * @sec_ctx contains the security context information being provided by * the user-level policy update program (e.g., setkey). * Allocate a security structure to the xp->security field; the security * field is initialized to NULL when the xfrm_policy is allocated. * Return 0 if operation was successful (memory to allocate, legal context) * @xfrm_policy_clone_security: - * @old_ctx contains an existing xfrm_sec_ctx. - * @new_ctxp contains a new xfrm_sec_ctx being cloned from old. - * Allocate a security structure in new_ctxp that contains the - * information from the old_ctx structure. + * @old contains an existing xfrm_policy in the SPD. + * @new contains a new xfrm_policy being cloned from old. + * Allocate a security structure to the new->security field + * that contains the information from the old->security field. * Return 0 if operation was successful (memory to allocate). * @xfrm_policy_free_security: - * @ctx contains the xfrm_sec_ctx + * @xp contains the xfrm_policy * Deallocate xp->security. * @xfrm_policy_delete_security: - * @ctx contains the xfrm_sec_ctx. + * @xp contains the xfrm_policy. * Authorize deletion of xp->security. * @xfrm_state_alloc_security: * @x contains the xfrm_state being added to the Security Association @@ -947,7 +947,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) * @x contains the xfrm_state. * Authorize deletion of x->security. * @xfrm_policy_lookup: - * @ctx contains the xfrm_sec_ctx for which the access control is being + * @xp contains the xfrm_policy for which the access control is being * checked. * @fl_secid contains the flow security label that is used to authorize * access to the policy xp. @@ -1454,17 +1454,17 @@ struct security_operations { #endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM - int (*xfrm_policy_alloc_security) (struct xfrm_sec_ctx **ctxp, + int (*xfrm_policy_alloc_security) (struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx); - int (*xfrm_policy_clone_security) (struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctx); - void (*xfrm_policy_free_security) (struct xfrm_sec_ctx *ctx); - int (*xfrm_policy_delete_security) (struct xfrm_sec_ctx *ctx); + int (*xfrm_policy_clone_security) (struct xfrm_policy *old, struct xfrm_policy *new); + void (*xfrm_policy_free_security) (struct xfrm_policy *xp); + int (*xfrm_policy_delete_security) (struct xfrm_policy *xp); int (*xfrm_state_alloc_security) (struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx, u32 secid); void (*xfrm_state_free_security) (struct xfrm_state *x); int (*xfrm_state_delete_security) (struct xfrm_state *x); - int (*xfrm_policy_lookup)(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); + int (*xfrm_policy_lookup)(struct xfrm_policy *xp, u32 fl_secid, u8 dir); int (*xfrm_state_pol_flow_match)(struct xfrm_state *x, struct xfrm_policy *xp, struct flowi *fl); int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall); @@ -2562,16 +2562,16 @@ static inline void security_inet_conn_established(struct sock *sk, #ifdef CONFIG_SECURITY_NETWORK_XFRM -int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx); -int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp); -void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx); -int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); +int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx); +int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new); +void security_xfrm_policy_free(struct xfrm_policy *xp); +int security_xfrm_policy_delete(struct xfrm_policy *xp); int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx); int security_xfrm_state_alloc_acquire(struct xfrm_state *x, struct xfrm_sec_ctx *polsec, u32 secid); int security_xfrm_state_delete(struct xfrm_state *x); void security_xfrm_state_free(struct xfrm_state *x); -int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); +int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir); int security_xfrm_state_pol_flow_match(struct xfrm_state *x, struct xfrm_policy *xp, struct flowi *fl); int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid); @@ -2579,21 +2579,21 @@ void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl); #else /* CONFIG_SECURITY_NETWORK_XFRM */ -static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx) +static inline int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx) { return 0; } -static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp) +static inline int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new) { return 0; } -static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) +static inline void security_xfrm_policy_free(struct xfrm_policy *xp) { } -static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) +static inline int security_xfrm_policy_delete(struct xfrm_policy *xp) { return 0; } @@ -2619,7 +2619,7 @@ static inline int security_xfrm_state_delete(struct xfrm_state *x) return 0; } -static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) +static inline int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir) { return 0; } diff --git a/trunk/include/net/netlabel.h b/trunk/include/net/netlabel.h index 5e53a85b5ca1..0ca67d73c7ad 100644 --- a/trunk/include/net/netlabel.h +++ b/trunk/include/net/netlabel.h @@ -162,7 +162,7 @@ struct netlbl_lsm_secattr_catmap { /** * struct netlbl_lsm_secattr - NetLabel LSM security attributes - * @flags: indicate structure attributes, see NETLBL_SECATTR_* + * @flags: indicate which attributes are contained in this structure * @type: indicate the NLTYPE of the attributes * @domain: the NetLabel LSM domain * @cache: NetLabel LSM specific cache @@ -180,22 +180,17 @@ struct netlbl_lsm_secattr_catmap { * NetLabel itself when returning security attributes to the LSM. * */ -struct netlbl_lsm_secattr { - u32 flags; - /* bitmap values for 'flags' */ #define NETLBL_SECATTR_NONE 0x00000000 #define NETLBL_SECATTR_DOMAIN 0x00000001 -#define NETLBL_SECATTR_DOMAIN_CPY (NETLBL_SECATTR_DOMAIN | \ - NETLBL_SECATTR_FREE_DOMAIN) #define NETLBL_SECATTR_CACHE 0x00000002 #define NETLBL_SECATTR_MLS_LVL 0x00000004 #define NETLBL_SECATTR_MLS_CAT 0x00000008 #define NETLBL_SECATTR_SECID 0x00000010 - /* bitmap meta-values for 'flags' */ -#define NETLBL_SECATTR_FREE_DOMAIN 0x01000000 #define NETLBL_SECATTR_CACHEABLE (NETLBL_SECATTR_MLS_LVL | \ NETLBL_SECATTR_MLS_CAT | \ NETLBL_SECATTR_SECID) +struct netlbl_lsm_secattr { + u32 flags; u32 type; char *domain; struct netlbl_lsm_cache *cache; @@ -308,8 +303,7 @@ static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr) */ static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr) { - if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN) - kfree(secattr->domain); + kfree(secattr->domain); if (secattr->flags & NETLBL_SECATTR_CACHE) netlbl_secattr_cache_free(secattr->cache); if (secattr->flags & NETLBL_SECATTR_MLS_CAT) diff --git a/trunk/net/ipv6/ip6_input.c b/trunk/net/ipv6/ip6_input.c index 09a3201e408a..4e5c8615832c 100644 --- a/trunk/net/ipv6/ip6_input.c +++ b/trunk/net/ipv6/ip6_input.c @@ -262,21 +262,23 @@ int ip6_mc_input(struct sk_buff *skb) * is for MLD (0x0000). */ if ((ptr[2] | ptr[3]) == 0) { + deliver = 0; + if (!ipv6_ext_hdr(nexthdr)) { /* BUG */ - goto discard; + goto out; } offset = ipv6_skip_exthdr(skb, sizeof(*hdr), &nexthdr); if (offset < 0) - goto discard; + goto out; if (nexthdr != IPPROTO_ICMPV6) - goto discard; + goto out; if (!pskb_may_pull(skb, (skb_network_header(skb) + offset + 1 - skb->data))) - goto discard; + goto out; icmp6 = (struct icmp6hdr *)(skb_network_header(skb) + offset); @@ -285,12 +287,9 @@ int ip6_mc_input(struct sk_buff *skb) case ICMPV6_MGM_REPORT: case ICMPV6_MGM_REDUCTION: case ICMPV6_MLD2_REPORT: + deliver = 1; break; - default: - /* Bogus */ - goto discard; } - deliver = 1; goto out; } /* unknown RA - process it normally */ @@ -308,15 +307,14 @@ int ip6_mc_input(struct sk_buff *skb) ip6_mr_input(skb2); } } -#endif out: - if (likely(deliver)) { +#endif + if (likely(deliver)) ip6_input(skb); - return 0; + else { + /* discard */ + kfree_skb(skb); } -discard: - /* discard */ - kfree_skb(skb); return 0; } diff --git a/trunk/net/key/af_key.c b/trunk/net/key/af_key.c index 1fb0fe42a72e..6db58924368a 100644 --- a/trunk/net/key/af_key.c +++ b/trunk/net/key/af_key.c @@ -2292,7 +2292,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h goto out; } - err = security_xfrm_policy_alloc(&xp->security, uctx); + err = security_xfrm_policy_alloc(xp, uctx); kfree(uctx); if (err) @@ -2352,11 +2352,10 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg int err; struct sadb_address *sa; struct sadb_x_policy *pol; - struct xfrm_policy *xp; + struct xfrm_policy *xp, tmp; struct xfrm_selector sel; struct km_event c; struct sadb_x_sec_ctx *sec_ctx; - struct xfrm_sec_ctx *pol_ctx; if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC-1], ext_hdrs[SADB_EXT_ADDRESS_DST-1]) || @@ -2386,23 +2385,25 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, struct sadb_msg sel.dport_mask = htons(0xffff); sec_ctx = (struct sadb_x_sec_ctx *) ext_hdrs[SADB_X_EXT_SEC_CTX-1]; + memset(&tmp, 0, sizeof(struct xfrm_policy)); + if (sec_ctx != NULL) { struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); if (!uctx) return -ENOMEM; - err = security_xfrm_policy_alloc(&pol_ctx, uctx); + err = security_xfrm_policy_alloc(&tmp, uctx); kfree(uctx); + if (err) return err; - } else - pol_ctx = NULL; + } + + xp = xfrm_policy_bysel_ctx(XFRM_POLICY_TYPE_MAIN, pol->sadb_x_policy_dir-1, + &sel, tmp.security, 1, &err); + security_xfrm_policy_free(&tmp); - xp = xfrm_policy_bysel_ctx(XFRM_POLICY_TYPE_MAIN, - pol->sadb_x_policy_dir - 1, &sel, pol_ctx, - 1, &err); - security_xfrm_policy_free(pol_ctx); if (xp == NULL) return -ENOENT; @@ -3297,7 +3298,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt, if ((*dir = verify_sec_ctx_len(p))) goto out; uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); - *dir = security_xfrm_policy_alloc(&xp->security, uctx); + *dir = security_xfrm_policy_alloc(xp, uctx); kfree(uctx); if (*dir) diff --git a/trunk/net/sctp/associola.c b/trunk/net/sctp/associola.c index b4cd2b71953f..422c98aa9d5c 100644 --- a/trunk/net/sctp/associola.c +++ b/trunk/net/sctp/associola.c @@ -718,11 +718,12 @@ struct sctp_transport *sctp_assoc_lookup_paddr( const union sctp_addr *address) { struct sctp_transport *t; + struct list_head *pos; /* Cycle through all transports searching for a peer address. */ - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if (sctp_cmp_addr_exact(address, &t->ipaddr)) return t; } @@ -761,6 +762,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc, struct sctp_transport *second; struct sctp_ulpevent *event; struct sockaddr_storage addr; + struct list_head *pos; int spc_state = 0; /* Record the transition on the transport. */ @@ -812,8 +814,8 @@ void sctp_assoc_control_transport(struct sctp_association *asoc, */ first = NULL; second = NULL; - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if ((t->state == SCTP_INACTIVE) || (t->state == SCTP_UNCONFIRMED)) @@ -930,6 +932,7 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc, { struct sctp_transport *active; struct sctp_transport *match; + struct list_head *entry, *pos; struct sctp_transport *transport; struct sctp_chunk *chunk; __be32 key = htonl(tsn); @@ -953,8 +956,8 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc, active = asoc->peer.active_path; - list_for_each_entry(chunk, &active->transmitted, - transmitted_list) { + list_for_each(entry, &active->transmitted) { + chunk = list_entry(entry, struct sctp_chunk, transmitted_list); if (key == chunk->subh.data_hdr->tsn) { match = active; @@ -963,13 +966,14 @@ struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *asoc, } /* If not found, go search all the other transports. */ - list_for_each_entry(transport, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + transport = list_entry(pos, struct sctp_transport, transports); if (transport == active) break; - list_for_each_entry(chunk, &transport->transmitted, - transmitted_list) { + list_for_each(entry, &transport->transmitted) { + chunk = list_entry(entry, struct sctp_chunk, + transmitted_list); if (key == chunk->subh.data_hdr->tsn) { match = transport; goto out; @@ -1150,8 +1154,9 @@ void sctp_assoc_update(struct sctp_association *asoc, } else { /* Add any peer addresses from the new association. */ - list_for_each_entry(trans, &new->peer.transport_addr_list, - transports) { + list_for_each(pos, &new->peer.transport_addr_list) { + trans = list_entry(pos, struct sctp_transport, + transports); if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr)) sctp_assoc_add_peer(asoc, &trans->ipaddr, GFP_ATOMIC, trans->state); @@ -1301,14 +1306,15 @@ struct sctp_transport *sctp_assoc_choose_shutdown_transport( void sctp_assoc_sync_pmtu(struct sctp_association *asoc) { struct sctp_transport *t; + struct list_head *pos; __u32 pmtu = 0; if (!asoc) return; /* Get the lowest pmtu of all the transports. */ - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if (t->pmtu_pending && t->dst) { sctp_transport_update_pmtu(t, dst_mtu(t->dst)); t->pmtu_pending = 0; diff --git a/trunk/net/sctp/bind_addr.c b/trunk/net/sctp/bind_addr.c index 80e6df06967a..ceefda025e2d 100644 --- a/trunk/net/sctp/bind_addr.c +++ b/trunk/net/sctp/bind_addr.c @@ -67,13 +67,15 @@ int sctp_bind_addr_copy(struct sctp_bind_addr *dest, int flags) { struct sctp_sockaddr_entry *addr; + struct list_head *pos; int error = 0; /* All addresses share the same port. */ dest->port = src->port; /* Extract the addresses which are relevant for this scope. */ - list_for_each_entry(addr, &src->address_list, list) { + list_for_each(pos, &src->address_list) { + addr = list_entry(pos, struct sctp_sockaddr_entry, list); error = sctp_copy_one_addr(dest, &addr->a, scope, gfp, flags); if (error < 0) @@ -85,7 +87,9 @@ int sctp_bind_addr_copy(struct sctp_bind_addr *dest, * the assumption that we must be sitting behind a NAT. */ if (list_empty(&dest->address_list) && (SCTP_SCOPE_GLOBAL == scope)) { - list_for_each_entry(addr, &src->address_list, list) { + list_for_each(pos, &src->address_list) { + addr = list_entry(pos, struct sctp_sockaddr_entry, + list); error = sctp_copy_one_addr(dest, &addr->a, SCTP_SCOPE_LINK, gfp, flags); @@ -111,12 +115,14 @@ int sctp_bind_addr_dup(struct sctp_bind_addr *dest, gfp_t gfp) { struct sctp_sockaddr_entry *addr; + struct list_head *pos; int error = 0; /* All addresses share the same port. */ dest->port = src->port; - list_for_each_entry(addr, &src->address_list, list) { + list_for_each(pos, &src->address_list) { + addr = list_entry(pos, struct sctp_sockaddr_entry, list); error = sctp_add_bind_addr(dest, &addr->a, 1, gfp); if (error < 0) break; @@ -267,7 +273,8 @@ union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp, addrparms = retval; - list_for_each_entry(addr, &bp->address_list, list) { + list_for_each(pos, &bp->address_list) { + addr = list_entry(pos, struct sctp_sockaddr_entry, list); af = sctp_get_af_specific(addr->a.v4.sin_family); len = af->to_addr_param(&addr->a, &rawaddr); memcpy(addrparms.v, &rawaddr, len); diff --git a/trunk/net/sctp/outqueue.c b/trunk/net/sctp/outqueue.c index 213c2e2926a9..392012f5ab83 100644 --- a/trunk/net/sctp/outqueue.c +++ b/trunk/net/sctp/outqueue.c @@ -221,12 +221,12 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q) void sctp_outq_teardown(struct sctp_outq *q) { struct sctp_transport *transport; - struct list_head *lchunk, *temp; + struct list_head *lchunk, *pos, *temp; struct sctp_chunk *chunk, *tmp; /* Throw away unacknowledged chunks. */ - list_for_each_entry(transport, &q->asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &q->asoc->peer.transport_addr_list) { + transport = list_entry(pos, struct sctp_transport, transports); while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) { chunk = list_entry(lchunk, struct sctp_chunk, transmitted_list); @@ -538,7 +538,7 @@ static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt, int rtx_timeout, int *start_timer) { struct list_head *lqueue; - struct list_head *lchunk; + struct list_head *lchunk, *lchunk1; struct sctp_transport *transport = pkt->transport; sctp_xmit_t status; struct sctp_chunk *chunk, *chunk1; @@ -649,7 +649,9 @@ static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt, * to be marked as ineligible for a subsequent fast retransmit. */ if (rtx_timeout && !lchunk) { - list_for_each_entry(chunk1, lqueue, transmitted_list) { + list_for_each(lchunk1, lqueue) { + chunk1 = list_entry(lchunk1, struct sctp_chunk, + transmitted_list); if (chunk1->fast_retransmit > 0) chunk1->fast_retransmit = -1; } @@ -1035,6 +1037,7 @@ static void sctp_sack_update_unack_data(struct sctp_association *assoc, static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack, struct sctp_association *asoc) { + struct list_head *ltransport, *lchunk; struct sctp_transport *transport; struct sctp_chunk *chunk; __u32 highest_new_tsn, tsn; @@ -1042,9 +1045,12 @@ static __u32 sctp_highest_new_tsn(struct sctp_sackhdr *sack, highest_new_tsn = ntohl(sack->cum_tsn_ack); - list_for_each_entry(transport, transport_list, transports) { - list_for_each_entry(chunk, &transport->transmitted, - transmitted_list) { + list_for_each(ltransport, transport_list) { + transport = list_entry(ltransport, struct sctp_transport, + transports); + list_for_each(lchunk, &transport->transmitted) { + chunk = list_entry(lchunk, struct sctp_chunk, + transmitted_list); tsn = ntohl(chunk->subh.data_hdr->tsn); if (!chunk->tsn_gap_acked && @@ -1067,7 +1073,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) struct sctp_association *asoc = q->asoc; struct sctp_transport *transport; struct sctp_chunk *tchunk = NULL; - struct list_head *lchunk, *transport_list, *temp; + struct list_head *lchunk, *transport_list, *pos, *temp; sctp_sack_variable_t *frags = sack->variable; __u32 sack_ctsn, ctsn, tsn; __u32 highest_tsn, highest_new_tsn; @@ -1093,8 +1099,9 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) */ if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) { primary->cacc.changeover_active = 0; - list_for_each_entry(transport, transport_list, - transports) { + list_for_each(pos, transport_list) { + transport = list_entry(pos, struct sctp_transport, + transports); transport->cacc.cycling_changeover = 0; } } @@ -1109,7 +1116,9 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) */ if (sack->num_gap_ack_blocks && primary->cacc.changeover_active) { - list_for_each_entry(transport, transport_list, transports) { + list_for_each(pos, transport_list) { + transport = list_entry(pos, struct sctp_transport, + transports); transport->cacc.cacc_saw_newack = 0; } } @@ -1138,7 +1147,9 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) * * This is a MASSIVE candidate for optimization. */ - list_for_each_entry(transport, transport_list, transports) { + list_for_each(pos, transport_list) { + transport = list_entry(pos, struct sctp_transport, + transports); sctp_check_transmitted(q, &transport->transmitted, transport, sack, highest_new_tsn); /* @@ -1150,7 +1161,9 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) count_of_newacks ++; } - list_for_each_entry(transport, transport_list, transports) { + list_for_each(pos, transport_list) { + transport = list_entry(pos, struct sctp_transport, + transports); sctp_mark_missing(q, &transport->transmitted, transport, highest_new_tsn, count_of_newacks); } @@ -1207,7 +1220,9 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_sackhdr *sack) if (!q->empty) goto finish; - list_for_each_entry(transport, transport_list, transports) { + list_for_each(pos, transport_list) { + transport = list_entry(pos, struct sctp_transport, + transports); q->empty = q->empty && list_empty(&transport->transmitted); if (!q->empty) goto finish; @@ -1581,12 +1596,14 @@ static void sctp_mark_missing(struct sctp_outq *q, int count_of_newacks) { struct sctp_chunk *chunk; + struct list_head *pos; __u32 tsn; char do_fast_retransmit = 0; struct sctp_transport *primary = q->asoc->peer.primary_path; - list_for_each_entry(chunk, transmitted_queue, transmitted_list) { + list_for_each(pos, transmitted_queue) { + chunk = list_entry(pos, struct sctp_chunk, transmitted_list); tsn = ntohl(chunk->subh.data_hdr->tsn); /* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all diff --git a/trunk/net/sctp/proc.c b/trunk/net/sctp/proc.c index 0aba759cb9b7..ddca90e5e3a5 100644 --- a/trunk/net/sctp/proc.c +++ b/trunk/net/sctp/proc.c @@ -124,6 +124,7 @@ void sctp_snmp_proc_exit(void) /* Dump local addresses of an association/endpoint. */ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb) { + struct list_head *pos; struct sctp_association *asoc; struct sctp_sockaddr_entry *laddr; struct sctp_transport *peer; @@ -136,7 +137,8 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo primary = &peer->saddr; } - list_for_each_entry(laddr, &epb->bind_addr.address_list, list) { + list_for_each(pos, &epb->bind_addr.address_list) { + laddr = list_entry(pos, struct sctp_sockaddr_entry, list); addr = &laddr->a; af = sctp_get_af_specific(addr->sa.sa_family); if (primary && af->cmp_addr(addr, primary)) { @@ -149,13 +151,14 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo /* Dump remote addresses of an association. */ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc) { + struct list_head *pos; struct sctp_transport *transport; union sctp_addr *addr, *primary; struct sctp_af *af; primary = &assoc->peer.primary_addr; - list_for_each_entry(transport, &assoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &assoc->peer.transport_addr_list) { + transport = list_entry(pos, struct sctp_transport, transports); addr = &transport->ipaddr; af = sctp_get_af_specific(addr->sa.sa_family); if (af->cmp_addr(addr, primary)) { @@ -319,7 +322,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v) sk = epb->sk; seq_printf(seq, "%8p %8p %-3d %-3d %-2d %-4d " - "%4d %8d %8d %7d %5lu %-5d %5d ", + "%4d %8d %8d %7d %5lu %-5d %5d " + "%8lu %5d %5d %4d %4d %4d %8d ", assoc, sk, sctp_sk(sk)->type, sk->sk_state, assoc->state, hash, assoc->assoc_id, @@ -327,16 +331,15 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v) atomic_read(&assoc->rmem_alloc), sock_i_uid(sk), sock_i_ino(sk), epb->bind_addr.port, - assoc->peer.port); + assoc->peer.port, + assoc->hbinterval, assoc->c.sinit_max_instreams, + assoc->c.sinit_num_ostreams, assoc->max_retrans, + assoc->init_retries, assoc->shutdown_retries, + assoc->rtx_data_chunks); seq_printf(seq, " "); sctp_seq_dump_local_addrs(seq, epb); seq_printf(seq, "<-> "); sctp_seq_dump_remote_addrs(seq, assoc); - seq_printf(seq, "\t%8lu %5d %5d %4d %4d %4d %8d ", - assoc->hbinterval, assoc->c.sinit_max_instreams, - assoc->c.sinit_num_ostreams, assoc->max_retrans, - assoc->init_retries, assoc->shutdown_retries, - assoc->rtx_data_chunks); seq_printf(seq, "\n"); } read_unlock(&head->lock); diff --git a/trunk/net/sctp/sm_make_chunk.c b/trunk/net/sctp/sm_make_chunk.c index 0679bddf3a95..c8982452580e 100644 --- a/trunk/net/sctp/sm_make_chunk.c +++ b/trunk/net/sctp/sm_make_chunk.c @@ -2246,8 +2246,8 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid, * high (for example, implementations MAY use the size of the receiver * advertised window). */ - list_for_each_entry(transport, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + transport = list_entry(pos, struct sctp_transport, transports); transport->ssthresh = asoc->peer.i.a_rwnd; } @@ -3043,6 +3043,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc, union sctp_addr addr; struct sctp_bind_addr *bp = &asoc->base.bind_addr; union sctp_addr_param *addr_param; + struct list_head *pos; struct sctp_transport *transport; struct sctp_sockaddr_entry *saddr; int retval = 0; @@ -3070,8 +3071,9 @@ static int sctp_asconf_param_success(struct sctp_association *asoc, local_bh_disable(); retval = sctp_del_bind_addr(bp, &addr); local_bh_enable(); - list_for_each_entry(transport, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + transport = list_entry(pos, struct sctp_transport, + transports); dst_release(transport->dst); sctp_transport_route(transport, NULL, sctp_sk(asoc->base.sk)); diff --git a/trunk/net/sctp/sm_sideeffect.c b/trunk/net/sctp/sm_sideeffect.c index 13beed263e31..02bf32c30263 100644 --- a/trunk/net/sctp/sm_sideeffect.c +++ b/trunk/net/sctp/sm_sideeffect.c @@ -545,12 +545,14 @@ static void sctp_cmd_hb_timers_start(sctp_cmd_seq_t *cmds, struct sctp_association *asoc) { struct sctp_transport *t; + struct list_head *pos; /* Start a heartbeat timer for each transport on the association. * hold a reference on the transport to make sure none of * the needed data structures go away. */ - list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t))) sctp_transport_hold(t); @@ -561,11 +563,12 @@ static void sctp_cmd_hb_timers_stop(sctp_cmd_seq_t *cmds, struct sctp_association *asoc) { struct sctp_transport *t; + struct list_head *pos; /* Stop all heartbeat timers. */ - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if (del_timer(&t->hb_timer)) sctp_transport_put(t); } @@ -576,9 +579,10 @@ static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t *cmds, struct sctp_association *asoc) { struct sctp_transport *t; + struct list_head *pos; - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, transports); if (timer_pending(&t->T3_rtx_timer) && del_timer(&t->T3_rtx_timer)) { sctp_transport_put(t); @@ -589,6 +593,7 @@ static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t *cmds, /* Helper function to update the heartbeat timer. */ static void sctp_cmd_hb_timer_update(sctp_cmd_seq_t *cmds, + struct sctp_association *asoc, struct sctp_transport *t) { /* Update the heartbeat timer. */ @@ -1060,6 +1065,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type, struct sctp_chunk *new_obj; struct sctp_chunk *chunk = NULL; struct sctp_packet *packet; + struct list_head *pos; struct timer_list *timer; unsigned long timeout; struct sctp_transport *t; @@ -1391,8 +1397,9 @@ static int sctp_cmd_interpreter(sctp_event_t event_type, /* If we've sent any data bundled with * COOKIE-ECHO we need to resend. */ - list_for_each_entry(t, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + t = list_entry(pos, struct sctp_transport, + transports); sctp_retransmit_mark(&asoc->outqueue, t, SCTP_RTXR_T1_RTX); } @@ -1450,7 +1457,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type, case SCTP_CMD_HB_TIMER_UPDATE: t = cmd->obj.transport; - sctp_cmd_hb_timer_update(commands, t); + sctp_cmd_hb_timer_update(commands, asoc, t); break; case SCTP_CMD_HB_TIMERS_STOP: diff --git a/trunk/net/sctp/sm_statefuns.c b/trunk/net/sctp/sm_statefuns.c index 622284805500..b534dbef864f 100644 --- a/trunk/net/sctp/sm_statefuns.c +++ b/trunk/net/sctp/sm_statefuns.c @@ -1226,6 +1226,7 @@ static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, sctp_cmd_seq_t *commands) { struct sctp_transport *new_addr, *addr; + struct list_head *pos, *pos2; int found; /* Implementor's Guide - Sectin 5.2.2 @@ -1242,11 +1243,12 @@ static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, new_addr = NULL; found = 0; - list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &new_asoc->peer.transport_addr_list) { + new_addr = list_entry(pos, struct sctp_transport, transports); found = 0; - list_for_each_entry(addr, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos2, &asoc->peer.transport_addr_list) { + addr = list_entry(pos2, struct sctp_transport, + transports); if (sctp_cmp_addr_exact(&new_addr->ipaddr, &addr->ipaddr)) { found = 1; diff --git a/trunk/net/sctp/socket.c b/trunk/net/sctp/socket.c index 8c90289ba400..025f467d80dd 100644 --- a/trunk/net/sctp/socket.c +++ b/trunk/net/sctp/socket.c @@ -513,6 +513,7 @@ static int sctp_send_asconf_add_ip(struct sock *sk, union sctp_addr saveaddr; void *addr_buf; struct sctp_af *af; + struct list_head *pos; struct list_head *p; int i; int retval = 0; @@ -526,7 +527,8 @@ static int sctp_send_asconf_add_ip(struct sock *sk, SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", __func__, sk, addrs, addrcnt); - list_for_each_entry(asoc, &ep->asocs, asocs) { + list_for_each(pos, &ep->asocs) { + asoc = list_entry(pos, struct sctp_association, asocs); if (!asoc->peer.asconf_capable) continue; @@ -697,6 +699,7 @@ static int sctp_send_asconf_del_ip(struct sock *sk, union sctp_addr *laddr; void *addr_buf; struct sctp_af *af; + struct list_head *pos, *pos1; struct sctp_sockaddr_entry *saddr; int i; int retval = 0; @@ -710,7 +713,8 @@ static int sctp_send_asconf_del_ip(struct sock *sk, SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", __func__, sk, addrs, addrcnt); - list_for_each_entry(asoc, &ep->asocs, asocs) { + list_for_each(pos, &ep->asocs) { + asoc = list_entry(pos, struct sctp_association, asocs); if (!asoc->peer.asconf_capable) continue; @@ -783,8 +787,9 @@ static int sctp_send_asconf_del_ip(struct sock *sk, * as some of the addresses in the bind address list are * about to be deleted and cannot be used as source addresses. */ - list_for_each_entry(transport, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos1, &asoc->peer.transport_addr_list) { + transport = list_entry(pos1, struct sctp_transport, + transports); dst_release(transport->dst); sctp_transport_route(transport, NULL, sctp_sk(asoc->base.sk)); @@ -1392,6 +1397,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, long timeo; __u16 sinfo_flags = 0; struct sctp_datamsg *datamsg; + struct list_head *pos; int msg_flags = msg->msg_flags; SCTP_DEBUG_PRINTK("sctp_sendmsg(sk: %p, msg: %p, msg_len: %zu)\n", @@ -1721,7 +1727,8 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, } /* Now send the (possibly) fragmented message. */ - list_for_each_entry(chunk, &datamsg->chunks, frag_list) { + list_for_each(pos, &datamsg->chunks) { + chunk = list_entry(pos, struct sctp_chunk, frag_list); sctp_chunk_hold(chunk); /* Do accounting for the write space. */ @@ -2294,8 +2301,11 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, * transport. */ if (!trans && asoc) { - list_for_each_entry(trans, &asoc->peer.transport_addr_list, - transports) { + struct list_head *pos; + + list_for_each(pos, &asoc->peer.transport_addr_list) { + trans = list_entry(pos, struct sctp_transport, + transports); sctp_apply_peer_addr_params(¶ms, trans, asoc, sp, hb_change, pmtud_change, sackdelay_change); @@ -2386,8 +2396,11 @@ static int sctp_setsockopt_delayed_ack_time(struct sock *sk, /* If change is for association, also apply to each transport. */ if (asoc) { - list_for_each_entry(trans, &asoc->peer.transport_addr_list, - transports) { + struct list_head *pos; + + list_for_each(pos, &asoc->peer.transport_addr_list) { + trans = list_entry(pos, struct sctp_transport, + transports); if (params.assoc_value) { trans->sackdelay = msecs_to_jiffies(params.assoc_value); @@ -2619,10 +2632,13 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int o if (assocparams.sasoc_asocmaxrxt != 0) { __u32 path_sum = 0; int paths = 0; + struct list_head *pos; struct sctp_transport *peer_addr; - list_for_each_entry(peer_addr, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + peer_addr = list_entry(pos, + struct sctp_transport, + transports); path_sum += peer_addr->pathmaxrxt; paths++; } @@ -2700,6 +2716,7 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int op static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) { struct sctp_association *asoc; + struct list_head *pos; struct sctp_sock *sp = sctp_sk(sk); int val; @@ -2712,7 +2729,8 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optl sp->user_frag = val; /* Update the frag_point of the existing associations. */ - list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { + list_for_each(pos, &(sp->ep->asocs)) { + asoc = list_entry(pos, struct sctp_association, asocs); asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu); } @@ -4133,6 +4151,7 @@ static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len, int __user *optlen) { struct sctp_association *asoc; + struct list_head *pos; int cnt = 0; struct sctp_getaddrs_old getaddrs; struct sctp_transport *from; @@ -4157,8 +4176,8 @@ static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len, return -EINVAL; to = (void __user *)getaddrs.addrs; - list_for_each_entry(from, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + from = list_entry(pos, struct sctp_transport, transports); memcpy(&temp, &from->ipaddr, sizeof(temp)); sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; @@ -4181,6 +4200,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, char __user *optval, int __user *optlen) { struct sctp_association *asoc; + struct list_head *pos; int cnt = 0; struct sctp_getaddrs getaddrs; struct sctp_transport *from; @@ -4205,8 +4225,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, to = optval + offsetof(struct sctp_getaddrs,addrs); space_left = len - offsetof(struct sctp_getaddrs,addrs); - list_for_each_entry(from, &asoc->peer.transport_addr_list, - transports) { + list_for_each(pos, &asoc->peer.transport_addr_list) { + from = list_entry(pos, struct sctp_transport, transports); memcpy(&temp, &from->ipaddr, sizeof(temp)); sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; @@ -6173,9 +6193,11 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, void sctp_write_space(struct sock *sk) { struct sctp_association *asoc; + struct list_head *pos; /* Wake up the tasks in each wait queue. */ - list_for_each_entry(asoc, &((sctp_sk(sk))->ep->asocs), asocs) { + list_for_each(pos, &((sctp_sk(sk))->ep->asocs)) { + asoc = list_entry(pos, struct sctp_association, asocs); __sctp_write_space(asoc); } } diff --git a/trunk/net/unix/af_unix.c b/trunk/net/unix/af_unix.c index 2851d0d15048..50bbf6bb1a22 100644 --- a/trunk/net/unix/af_unix.c +++ b/trunk/net/unix/af_unix.c @@ -2037,7 +2037,7 @@ static void *unix_seq_start(struct seq_file *seq, loff_t *pos) __acquires(unix_table_lock) { spin_lock(&unix_table_lock); - return *pos ? unix_seq_idx(seq, *pos - 1) : SEQ_START_TOKEN; + return *pos ? unix_seq_idx(seq, *pos - 1) : ((void *) 1); } static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) @@ -2046,7 +2046,7 @@ static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) struct sock *sk = v; ++*pos; - if (v == SEQ_START_TOKEN) + if (v == (void *)1) sk = first_unix_socket(&iter->i); else sk = next_unix_socket(&iter->i, sk); @@ -2064,7 +2064,7 @@ static void unix_seq_stop(struct seq_file *seq, void *v) static int unix_seq_show(struct seq_file *seq, void *v) { - if (v == SEQ_START_TOKEN) + if (v == (void *)1) seq_puts(seq, "Num RefCount Protocol Flags Type St " "Inode Path\n"); else { diff --git a/trunk/net/xfrm/xfrm_policy.c b/trunk/net/xfrm/xfrm_policy.c index ab4d0e598a2c..15d73e47cc2c 100644 --- a/trunk/net/xfrm/xfrm_policy.c +++ b/trunk/net/xfrm/xfrm_policy.c @@ -263,7 +263,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy) list_del(&policy->bytype); write_unlock_bh(&xfrm_policy_lock); - security_xfrm_policy_free(policy->security); + security_xfrm_policy_free(policy); kfree(policy); } EXPORT_SYMBOL(xfrm_policy_destroy); @@ -676,8 +676,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir, xfrm_sec_ctx_match(ctx, pol->security)) { xfrm_pol_hold(pol); if (delete) { - *err = security_xfrm_policy_delete( - pol->security); + *err = security_xfrm_policy_delete(pol); if (*err) { write_unlock_bh(&xfrm_policy_lock); return pol; @@ -719,8 +718,7 @@ struct xfrm_policy *xfrm_policy_byid(u8 type, int dir, u32 id, int delete, if (pol->type == type && pol->index == id) { xfrm_pol_hold(pol); if (delete) { - *err = security_xfrm_policy_delete( - pol->security); + *err = security_xfrm_policy_delete(pol); if (*err) { write_unlock_bh(&xfrm_policy_lock); return pol; @@ -758,7 +756,7 @@ xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info) &xfrm_policy_inexact[dir], bydst) { if (pol->type != type) continue; - err = security_xfrm_policy_delete(pol->security); + err = security_xfrm_policy_delete(pol); if (err) { xfrm_audit_policy_delete(pol, 0, audit_info->loginuid, @@ -772,8 +770,7 @@ xfrm_policy_flush_secctx_check(u8 type, struct xfrm_audit *audit_info) bydst) { if (pol->type != type) continue; - err = security_xfrm_policy_delete( - pol->security); + err = security_xfrm_policy_delete(pol); if (err) { xfrm_audit_policy_delete(pol, 0, audit_info->loginuid, @@ -934,8 +931,7 @@ static int xfrm_policy_match(struct xfrm_policy *pol, struct flowi *fl, match = xfrm_selector_match(sel, fl, family); if (match) - ret = security_xfrm_policy_lookup(pol->security, fl->secid, - dir); + ret = security_xfrm_policy_lookup(pol, fl->secid, dir); return ret; } @@ -1052,9 +1048,8 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, struc int err = 0; if (match) { - err = security_xfrm_policy_lookup(pol->security, - fl->secid, - policy_to_flow_dir(dir)); + err = security_xfrm_policy_lookup(pol, fl->secid, + policy_to_flow_dir(dir)); if (!err) xfrm_pol_hold(pol); else if (err == -ESRCH) @@ -1143,8 +1138,7 @@ static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir) if (newp) { newp->selector = old->selector; - if (security_xfrm_policy_clone(old->security, - &newp->security)) { + if (security_xfrm_policy_clone(old, newp)) { kfree(newp); return NULL; /* ENOMEM */ } diff --git a/trunk/net/xfrm/xfrm_user.c b/trunk/net/xfrm/xfrm_user.c index ecf9d67daef5..5578c909fcf6 100644 --- a/trunk/net/xfrm/xfrm_user.c +++ b/trunk/net/xfrm/xfrm_user.c @@ -959,7 +959,7 @@ static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct nlattr **attrs return 0; uctx = nla_data(rt); - return security_xfrm_policy_alloc(&pol->security, uctx); + return security_xfrm_policy_alloc(pol, uctx); } static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut, @@ -1143,7 +1143,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, NETLINK_CB(skb).sid); if (err) { - security_xfrm_policy_free(xp->security); + security_xfrm_policy_free(xp); kfree(xp); return err; } @@ -1337,23 +1337,22 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err); else { struct nlattr *rt = attrs[XFRMA_SEC_CTX]; - struct xfrm_sec_ctx *ctx; + struct xfrm_policy tmp; err = verify_sec_ctx_len(attrs); if (err) return err; + memset(&tmp, 0, sizeof(struct xfrm_policy)); if (rt) { struct xfrm_user_sec_ctx *uctx = nla_data(rt); - err = security_xfrm_policy_alloc(&ctx, uctx); - if (err) + if ((err = security_xfrm_policy_alloc(&tmp, uctx))) return err; - } else - ctx = NULL; - xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, ctx, + } + xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security, delete, &err); - security_xfrm_policy_free(ctx); + security_xfrm_policy_free(&tmp); } if (xp == NULL) return -ENOENT; @@ -1573,26 +1572,26 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err); else { struct nlattr *rt = attrs[XFRMA_SEC_CTX]; - struct xfrm_sec_ctx *ctx; + struct xfrm_policy tmp; err = verify_sec_ctx_len(attrs); if (err) return err; + memset(&tmp, 0, sizeof(struct xfrm_policy)); if (rt) { struct xfrm_user_sec_ctx *uctx = nla_data(rt); - err = security_xfrm_policy_alloc(&ctx, uctx); - if (err) + if ((err = security_xfrm_policy_alloc(&tmp, uctx))) return err; - } else - ctx = NULL; - xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, ctx, 0, &err); - security_xfrm_policy_free(ctx); + } + xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security, + 0, &err); + security_xfrm_policy_free(&tmp); } + if (xp == NULL) return -ENOENT; - read_lock(&xp->lock); if (xp->dead) { read_unlock(&xp->lock); diff --git a/trunk/security/dummy.c b/trunk/security/dummy.c index 480366f9c41d..78d8f92310a4 100644 --- a/trunk/security/dummy.c +++ b/trunk/security/dummy.c @@ -876,23 +876,22 @@ static inline void dummy_req_classify_flow(const struct request_sock *req, #endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM -static int dummy_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp, - struct xfrm_user_sec_ctx *sec_ctx) +static int dummy_xfrm_policy_alloc_security(struct xfrm_policy *xp, + struct xfrm_user_sec_ctx *sec_ctx) { return 0; } -static inline int dummy_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx, - struct xfrm_sec_ctx **new_ctxp) +static inline int dummy_xfrm_policy_clone_security(struct xfrm_policy *old, struct xfrm_policy *new) { return 0; } -static void dummy_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx) +static void dummy_xfrm_policy_free_security(struct xfrm_policy *xp) { } -static int dummy_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx) +static int dummy_xfrm_policy_delete_security(struct xfrm_policy *xp) { return 0; } @@ -912,8 +911,7 @@ static int dummy_xfrm_state_delete_security(struct xfrm_state *x) return 0; } -static int dummy_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, - u32 sk_sid, u8 dir) +static int dummy_xfrm_policy_lookup(struct xfrm_policy *xp, u32 sk_sid, u8 dir) { return 0; } diff --git a/trunk/security/security.c b/trunk/security/security.c index c9ff7d18c2f4..b1387a6b416d 100644 --- a/trunk/security/security.c +++ b/trunk/security/security.c @@ -1014,27 +1014,26 @@ void security_inet_conn_established(struct sock *sk, #ifdef CONFIG_SECURITY_NETWORK_XFRM -int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx) +int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx) { - return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx); + return security_ops->xfrm_policy_alloc_security(xp, sec_ctx); } EXPORT_SYMBOL(security_xfrm_policy_alloc); -int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, - struct xfrm_sec_ctx **new_ctxp) +int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new) { - return security_ops->xfrm_policy_clone_security(old_ctx, new_ctxp); + return security_ops->xfrm_policy_clone_security(old, new); } -void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) +void security_xfrm_policy_free(struct xfrm_policy *xp) { - security_ops->xfrm_policy_free_security(ctx); + security_ops->xfrm_policy_free_security(xp); } EXPORT_SYMBOL(security_xfrm_policy_free); -int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) +int security_xfrm_policy_delete(struct xfrm_policy *xp) { - return security_ops->xfrm_policy_delete_security(ctx); + return security_ops->xfrm_policy_delete_security(xp); } int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx) @@ -1066,9 +1065,9 @@ void security_xfrm_state_free(struct xfrm_state *x) security_ops->xfrm_state_free_security(x); } -int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) +int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir) { - return security_ops->xfrm_policy_lookup(ctx, fl_secid, dir); + return security_ops->xfrm_policy_lookup(xp, fl_secid, dir); } int security_xfrm_state_pol_flow_match(struct xfrm_state *x, diff --git a/trunk/security/selinux/include/xfrm.h b/trunk/security/selinux/include/xfrm.h index 289e24b39e3e..36b0510efa7b 100644 --- a/trunk/security/selinux/include/xfrm.h +++ b/trunk/security/selinux/include/xfrm.h @@ -7,17 +7,16 @@ #ifndef _SELINUX_XFRM_H_ #define _SELINUX_XFRM_H_ -int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, - struct xfrm_user_sec_ctx *sec_ctx); -int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, - struct xfrm_sec_ctx **new_ctxp); -void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); -int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); +int selinux_xfrm_policy_alloc(struct xfrm_policy *xp, + struct xfrm_user_sec_ctx *sec_ctx); +int selinux_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new); +void selinux_xfrm_policy_free(struct xfrm_policy *xp); +int selinux_xfrm_policy_delete(struct xfrm_policy *xp); int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx, u32 secid); void selinux_xfrm_state_free(struct xfrm_state *x); int selinux_xfrm_state_delete(struct xfrm_state *x); -int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); +int selinux_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir); int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x, struct xfrm_policy *xp, struct flowi *fl); diff --git a/trunk/security/selinux/ss/services.c b/trunk/security/selinux/ss/services.c index 47295acd09c9..f37418601215 100644 --- a/trunk/security/selinux/ss/services.c +++ b/trunk/security/selinux/ss/services.c @@ -2649,7 +2649,7 @@ int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr) goto netlbl_sid_to_secattr_failure; secattr->domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1], GFP_ATOMIC); - secattr->flags |= NETLBL_SECATTR_DOMAIN_CPY; + secattr->flags |= NETLBL_SECATTR_DOMAIN; mls_export_netlbl_lvl(ctx, secattr); rc = mls_export_netlbl_cat(ctx, secattr); if (rc != 0) diff --git a/trunk/security/selinux/xfrm.c b/trunk/security/selinux/xfrm.c index 874d17c83c61..7e158205d081 100644 --- a/trunk/security/selinux/xfrm.c +++ b/trunk/security/selinux/xfrm.c @@ -77,18 +77,20 @@ static inline int selinux_authorizable_xfrm(struct xfrm_state *x) * LSM hook implementation that authorizes that a flow can use * a xfrm policy rule. */ -int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) +int selinux_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir) { int rc; u32 sel_sid; + struct xfrm_sec_ctx *ctx; /* Context sid is either set to label or ANY_ASSOC */ - if (ctx) { + if ((ctx = xp->security)) { if (!selinux_authorizable_ctx(ctx)) return -EINVAL; sel_sid = ctx->ctx_sid; - } else + } + else /* * All flows should be treated as polmatch'ing an * otherwise applicable "non-labeled" policy. This @@ -101,7 +103,7 @@ int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) NULL); if (rc == -EACCES) - return -ESRCH; + rc = -ESRCH; return rc; } @@ -285,14 +287,15 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp, * LSM hook implementation that allocs and transfers uctx spec to * xfrm_policy. */ -int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, - struct xfrm_user_sec_ctx *uctx) +int selinux_xfrm_policy_alloc(struct xfrm_policy *xp, + struct xfrm_user_sec_ctx *uctx) { int err; + BUG_ON(!xp); BUG_ON(!uctx); - err = selinux_xfrm_sec_ctx_alloc(ctxp, uctx, 0); + err = selinux_xfrm_sec_ctx_alloc(&xp->security, uctx, 0); if (err == 0) atomic_inc(&selinux_xfrm_refcount); @@ -304,29 +307,32 @@ int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, * LSM hook implementation that copies security data structure from old to * new for policy cloning. */ -int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, - struct xfrm_sec_ctx **new_ctxp) +int selinux_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new) { - struct xfrm_sec_ctx *new_ctx; + struct xfrm_sec_ctx *old_ctx, *new_ctx; + + old_ctx = old->security; if (old_ctx) { - new_ctx = kmalloc(sizeof(*old_ctx) + old_ctx->ctx_len, - GFP_KERNEL); + new_ctx = new->security = kmalloc(sizeof(*new_ctx) + + old_ctx->ctx_len, + GFP_KERNEL); + if (!new_ctx) return -ENOMEM; memcpy(new_ctx, old_ctx, sizeof(*new_ctx)); memcpy(new_ctx->ctx_str, old_ctx->ctx_str, new_ctx->ctx_len); - *new_ctxp = new_ctx; } return 0; } /* - * LSM hook implementation that frees xfrm_sec_ctx security information. + * LSM hook implementation that frees xfrm_policy security information. */ -void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx) +void selinux_xfrm_policy_free(struct xfrm_policy *xp) { + struct xfrm_sec_ctx *ctx = xp->security; if (ctx) kfree(ctx); } @@ -334,9 +340,10 @@ void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx) /* * LSM hook implementation that authorizes deletion of labeled policies. */ -int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) +int selinux_xfrm_policy_delete(struct xfrm_policy *xp) { struct task_security_struct *tsec = current->security; + struct xfrm_sec_ctx *ctx = xp->security; int rc = 0; if (ctx) { diff --git a/trunk/security/smack/smack_lsm.c b/trunk/security/smack/smack_lsm.c index e2d6f7cd9254..732ba27923c4 100644 --- a/trunk/security/smack/smack_lsm.c +++ b/trunk/security/smack/smack_lsm.c @@ -1275,7 +1275,7 @@ static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp) switch (smack_net_nltype) { case NETLBL_NLTYPE_CIPSOV4: - nlsp->domain = smack; + nlsp->domain = kstrdup(smack, GFP_ATOMIC); nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL; rc = smack_to_cipso(smack, &cipso);