1. 03 12月, 2006 1 次提交
    • V
      SELinux: Fix SA selection semantics · 67f83cbf
      Venkat Yekkirala 提交于
      Fix the selection of an SA for an outgoing packet to be at the same
      context as the originating socket/flow. This eliminates the SELinux
      policy's ability to use/sendto SAs with contexts other than the socket's.
      
      With this patch applied, the SELinux policy will require one or more of the
      following for a socket to be able to communicate with/without SAs:
      
      1. To enable a socket to communicate without using labeled-IPSec SAs:
      
      allow socket_t unlabeled_t:association { sendto recvfrom }
      
      2. To enable a socket to communicate with labeled-IPSec SAs:
      
      allow socket_t self:association { sendto };
      allow socket_t peer_sa_t:association { recvfrom };
      Signed-off-by: NVenkat Yekkirala <vyekkirala@TrustedCS.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      67f83cbf
  2. 12 10月, 2006 3 次提交
    • V
      IPsec: fix handling of errors for socket policies · 3bccfbc7
      Venkat Yekkirala 提交于
      This treats the security errors encountered in the case of
      socket policy matching, the same as how these are treated in
      the case of main/sub policies, which is to return a full lookup
      failure.
      Signed-off-by: NVenkat Yekkirala <vyekkirala@TrustedCS.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      3bccfbc7
    • V
      IPsec: correct semantics for SELinux policy matching · 5b368e61
      Venkat Yekkirala 提交于
      Currently when an IPSec policy rule doesn't specify a security
      context, it is assumed to be "unlabeled" by SELinux, and so
      the IPSec policy rule fails to match to a flow that it would
      otherwise match to, unless one has explicitly added an SELinux
      policy rule allowing the flow to "polmatch" to the "unlabeled"
      IPSec policy rules. In the absence of such an explicitly added
      SELinux policy rule, the IPSec policy rule fails to match and
      so the packet(s) flow in clear text without the otherwise applicable
      xfrm(s) applied.
      
      The above SELinux behavior violates the SELinux security notion of
      "deny by default" which should actually translate to "encrypt by
      default" in the above case.
      
      This was first reported by Evgeniy Polyakov and the way James Morris
      was seeing the problem was when connecting via IPsec to a
      confined service on an SELinux box (vsftpd), which did not have the
      appropriate SELinux policy permissions to send packets via IPsec.
      
      With this patch applied, SELinux "polmatching" of flows Vs. IPSec
      policy rules will only come into play when there's a explicit context
      specified for the IPSec policy rule (which also means there's corresponding
      SELinux policy allowing appropriate domains/flows to polmatch to this context).
      
      Secondly, when a security module is loaded (in this case, SELinux), the
      security_xfrm_policy_lookup() hook can return errors other than access denied,
      such as -EINVAL.  We were not handling that correctly, and in fact
      inverting the return logic and propagating a false "ok" back up to
      xfrm_lookup(), which then allowed packets to pass as if they were not
      associated with an xfrm policy.
      
      The solution for this is to first ensure that errno values are
      correctly propagated all the way back up through the various call chains
      from security_xfrm_policy_lookup(), and handled correctly.
      
      Then, flow_cache_lookup() is modified, so that if the policy resolver
      fails (typically a permission denied via the security module), the flow
      cache entry is killed rather than having a null policy assigned (which
      indicates that the packet can pass freely).  This also forces any future
      lookups for the same flow to consult the security module (e.g. SELinux)
      for current security policy (rather than, say, caching the error on the
      flow cache entry).
      
      This patch: Fix the selinux side of things.
      
      This makes sure SELinux polmatching of flow contexts to IPSec policy
      rules comes into play only when an explicit context is associated
      with the IPSec policy rule.
      
      Also, this no longer defaults the context of a socket policy to
      the context of the socket since the "no explicit context" case
      is now handled properly.
      Signed-off-by: NVenkat Yekkirala <vyekkirala@TrustedCS.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      5b368e61
    • J
      IPsec: propagate security module errors up from flow_cache_lookup · 134b0fc5
      James Morris 提交于
      When a security module is loaded (in this case, SELinux), the
      security_xfrm_policy_lookup() hook can return an access denied permission
      (or other error).  We were not handling that correctly, and in fact
      inverting the return logic and propagating a false "ok" back up to
      xfrm_lookup(), which then allowed packets to pass as if they were not
      associated with an xfrm policy.
      
      The way I was seeing the problem was when connecting via IPsec to a
      confined service on an SELinux box (vsftpd), which did not have the
      appropriate SELinux policy permissions to send packets via IPsec.
      
      The first SYNACK would be blocked, because of an uncached lookup via
      flow_cache_lookup(), which would fail to resolve an xfrm policy because
      the SELinux policy is checked at that point via the resolver.
      
      However, retransmitted SYNACKs would then find a cached flow entry when
      calling into flow_cache_lookup() with a null xfrm policy, which is
      interpreted by xfrm_lookup() as the packet not having any associated
      policy and similarly to the first case, allowing it to pass without
      transformation.
      
      The solution presented here is to first ensure that errno values are
      correctly propagated all the way back up through the various call chains
      from security_xfrm_policy_lookup(), and handled correctly.
      
      Then, flow_cache_lookup() is modified, so that if the policy resolver
      fails (typically a permission denied via the security module), the flow
      cache entry is killed rather than having a null policy assigned (which
      indicates that the packet can pass freely).  This also forces any future
      lookups for the same flow to consult the security module (e.g. SELinux)
      for current security policy (rather than, say, caching the error on the
      flow cache entry).
      Signed-off-by: NJames Morris <jmorris@namei.org>
      134b0fc5
  3. 04 10月, 2006 1 次提交
  4. 23 9月, 2006 18 次提交
  5. 14 8月, 2006 1 次提交
    • D
      [IPSEC]: Validate properly in xfrm_dst_check() · d49c73c7
      David S. Miller 提交于
      If dst->obsolete is -1, this is a signal from the
      bundle creator that we want the XFRM dst and the
      dsts that it references to be validated on every
      use.
      
      I misunderstood this intention when I changed
      xfrm_dst_check() to always return NULL.
      
      Now, when we purge a dst entry, by running dst_free()
      on it.  This will set the dst->obsolete to a positive
      integer, and we want to return NULL in that case so
      that the socket does a relookup for the route.
      
      Thus, if dst->obsolete<0, let stale_bundle() validate
      the state, else always return NULL.
      
      In general, we need to do things more intelligently
      here because we flush too much state during rule
      changes.  Herbert Xu has some ideas wherein the key
      manager gives us some help in this area.  We can also
      use smarter state management algorithms inside of
      the kernel as well.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      d49c73c7
  6. 22 7月, 2006 1 次提交
  7. 01 7月, 2006 1 次提交
  8. 18 6月, 2006 2 次提交
    • H
      [IPSEC] xfrm: Abstract out encapsulation modes · b59f45d0
      Herbert Xu 提交于
      This patch adds the structure xfrm_mode.  It is meant to represent
      the operations carried out by transport/tunnel modes.
      
      By doing this we allow additional encapsulation modes to be added
      without clogging up the xfrm_input/xfrm_output paths.
      
      Candidate modes include 4-to-6 tunnel mode, 6-to-4 tunnel mode, and
      BEET modes.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b59f45d0
    • H
      [IPSEC] xfrm: Undo afinfo lock proliferation · 546be240
      Herbert Xu 提交于
      The number of locks used to manage afinfo structures can easily be reduced
      down to one each for policy and state respectively.  This is based on the
      observation that the write locks are only held by module insertion/removal
      which are very rare events so there is no need to further differentiate
      between the insertion of modules like ipv6 versus esp6.
      
      The removal of the read locks in xfrm4_policy.c/xfrm6_policy.c might look
      suspicious at first.  However, after you realise that nobody ever takes
      the corresponding write lock you'll feel better :)
      
      As far as I can gather it's an attempt to guard against the removal of
      the corresponding modules.  Since neither module can be unloaded at all
      we can leave it to whoever fixes up IPv6 unloading :)
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      546be240
  9. 30 4月, 2006 2 次提交
    • I
      [XFRM]: fix incorrect xfrm_policy_afinfo_lock use · e959d812
      Ingo Molnar 提交于
      xfrm_policy_afinfo_lock can be taken in bh context, at:
      
       [<c013fe1a>] lockdep_acquire_read+0x54/0x6d
       [<c0f6e024>] _read_lock+0x15/0x22
       [<c0e8fcdb>] xfrm_policy_get_afinfo+0x1a/0x3d
       [<c0e8fd10>] xfrm_decode_session+0x12/0x32
       [<c0e66094>] ip_route_me_harder+0x1c9/0x25b
       [<c0e770d3>] ip_nat_local_fn+0x94/0xad
       [<c0e2bbc8>] nf_iterate+0x2e/0x7a
       [<c0e2bc50>] nf_hook_slow+0x3c/0x9e
       [<c0e3a342>] ip_push_pending_frames+0x2de/0x3a7
       [<c0e53e19>] icmp_push_reply+0x136/0x141
       [<c0e543fb>] icmp_reply+0x118/0x1a0
       [<c0e54581>] icmp_echo+0x44/0x46
       [<c0e53fad>] icmp_rcv+0x111/0x138
       [<c0e36764>] ip_local_deliver+0x150/0x1f9
       [<c0e36be2>] ip_rcv+0x3d5/0x413
       [<c0df760f>] netif_receive_skb+0x337/0x356
       [<c0df76c3>] process_backlog+0x95/0x110
       [<c0df5fe2>] net_rx_action+0xa5/0x16d
       [<c012d8a7>] __do_softirq+0x6f/0xe6
       [<c0105ec2>] do_softirq+0x52/0xb1
      
      this means that all write-locking of xfrm_policy_afinfo_lock must be
      bh-safe. This patch fixes xfrm_policy_register_afinfo() and
      xfrm_policy_unregister_afinfo().
      Signed-off-by: NIngo Molnar <mingo@elte.hu>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      e959d812
    • I
      [XFRM]: fix softirq-unsafe xfrm typemap->lock use · 8dff7c29
      Ingo Molnar 提交于
      xfrm typemap->lock may be used in softirq context, so all write_lock()
      uses must be softirq-safe.
      Signed-off-by: NIngo Molnar <mingo@elte.hu>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      8dff7c29
  10. 01 4月, 2006 1 次提交
  11. 21 3月, 2006 3 次提交
  12. 28 2月, 2006 1 次提交
    • H
      [IPSEC]: Kill post_input hook and do NAT-T in esp_input directly · 752c1f4c
      Herbert Xu 提交于
      The only reason post_input exists at all is that it gives us the
      potential to adjust the checksums incrementally in future which
      we ought to do.
      
      However, after thinking about it for a bit we can adjust the
      checksums without using this post_input stuff at all.  The crucial
      point is that only the inner-most NAT-T SA needs to be considered
      when adjusting checksums.  What's more, the checksum adjustment
      comes down to a single u32 due to the linearity of IP checksums.
      
      We just happen to have a spare u32 lying around in our skb structure :)
      When ip_summed is set to CHECKSUM_NONE on input, the value of skb->csum
      is currently unused.  All we have to do is to make that the checksum
      adjustment and voila, there goes all the post_input and decap structures!
      
      I've left in the decap data structures for now since it's intricately
      woven into the sec_path stuff.  We can kill them later too.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      752c1f4c
  13. 24 2月, 2006 1 次提交
  14. 20 2月, 2006 1 次提交
    • P
      [XFRM]: Fix policy double put · 99511014
      Patrick McHardy 提交于
      The policy is put once immediately and once at the error label, which results
      in the following Oops:
      
      kernel BUG at net/xfrm/xfrm_policy.c:250!
      invalid opcode: 0000 [#2]
      PREEMPT
      [...]
      CPU:    0
      EIP:    0060:[<c028caf7>]    Not tainted VLI
      EFLAGS: 00210246   (2.6.16-rc3 #39)
      EIP is at __xfrm_policy_destroy+0xf/0x46
      eax: d49f2000   ebx: d49f2000   ecx: f74bd880   edx: f74bd280
      esi: d49f2000   edi: 00000001   ebp: cd506dcc   esp: cd506dc8
      ds: 007b   es: 007b   ss: 0068
      Process ssh (pid: 31970, threadinfo=cd506000 task=cfb04a70)
      Stack: <0>cd506000 cd506e34 c028e92b ebde7280 cd506e58 cd506ec0 f74bd280 00000000
             00000214 0000000a 0000000a 00000000 00000002 f7ae6000 00000000 cd506e58
             cd506e14 c0299e36 f74bd280 e873fe00 c02943fd cd506ec0 ebde7280 f271f440
      Call Trace:
       [<c0103a44>] show_stack_log_lvl+0xaa/0xb5
       [<c0103b75>] show_registers+0x126/0x18c
       [<c0103e68>] die+0x14e/0x1db
       [<c02b6809>] do_trap+0x7c/0x96
       [<c0104237>] do_invalid_op+0x89/0x93
       [<c01035af>] error_code+0x4f/0x54
       [<c028e92b>] xfrm_lookup+0x349/0x3c2
       [<c02b0b0d>] ip6_datagram_connect+0x317/0x452
       [<c0281749>] inet_dgram_connect+0x49/0x54
       [<c02404d2>] sys_connect+0x51/0x68
       [<c0240928>] sys_socketcall+0x6f/0x166
       [<c0102aa1>] syscall_call+0x7/0xb
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      99511014
  15. 14 2月, 2006 1 次提交
    • H
      [IPSEC]: Fix strange IPsec freeze. · 00de651d
      Herbert Xu 提交于
      Problem discovered and initial patch by Olaf Kirch:
      
      	there's a problem with IPsec that has been bugging some of our users
      	for the last couple of kernel revs. Every now and then, IPsec will
      	freeze the machine completely. This is with openswan user land,
      	and with kernels up to and including 2.6.16-rc2.
      
      	I managed to debug this a little, and what happens is that we end
      	up looping in xfrm_lookup, and never get out. With a bit of debug
      	printks added, I can this happening:
      
      		ip_route_output_flow calls xfrm_lookup
      
      		xfrm_find_bundle returns NULL (apparently we're in the
      			middle of negotiating a new SA or something)
      
      		We therefore call xfrm_tmpl_resolve. This returns EAGAIN
      			We go to sleep, waiting for a policy update.
      			Then we loop back to the top
      
      		Apparently, the dst_orig that was passed into xfrm_lookup
      			has been dropped from the routing table (obsolete=2)
      			This leads to the endless loop, because we now create
      			a new bundle, check the new bundle and find it's stale
      			(stale_bundle -> xfrm_bundle_ok -> dst_check() return 0)
      
      	People have been testing with the patch below, which seems to fix the
      	problem partially. They still see connection hangs however (things
      	only clear up when they start a new ping or new ssh). So the patch
      	is obvsiouly not sufficient, and something else seems to go wrong.
      
      	I'm grateful for any hints you may have...
      
      I suggest that we simply bail out always.  If the dst decides to die
      on us later on, the packet will be dropped anyway.  So there is no
      great urgency to retry here.  Once we have the proper resolution
      queueing, we can then do the retry again.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Acked-by: NOlaf Kirch <okir@suse.de>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      00de651d
  16. 08 2月, 2006 1 次提交
  17. 10 1月, 2006 1 次提交