05 Sep, 2018

1 commit

  • [ Upstream commit 7284fdf39a912322ce97de2d30def3c6068a418c ]

    This ought to be an omission in e6194923237 ("esp: Fix memleaks on error
    paths."). The memleak on error path in esp6_input is similar to esp_input
    of esp4.

    Fixes: e6194923237 ("esp: Fix memleaks on error paths.")
    Fixes: 3f29770723f ("ipsec: check return value of skb_to_sgvec always")
    Signed-off-by: Zhen Lei
    Signed-off-by: Steffen Klassert
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Zhen Lei
     

02 Sep, 2017

1 commit


31 Aug, 2017

1 commit

  • In conjunction with crypto offload [1], removing the ESP trailer by
    hardware can potentially improve the performance by avoiding (1) a
    cache miss incurred by reading the nexthdr field and (2) the necessity
    to calculate the csum value of the trailer in order to keep skb->csum
    valid.

    This patch introduces the changes to the xfrm stack and merely serves
    as an infrastructure. Subsequent patch to mlx5 driver will put this to
    a good use.

    [1] https://www.mail-archive.com/netdev@vger.kernel.org/msg175733.html

    Signed-off-by: Yossi Kuperman
    Signed-off-by: Steffen Klassert

    Yossi Kuperman
     

25 Aug, 2017

2 commits

  • We use skb_availroom to calculate the skb tailroom for the
    ESP trailer. skb_availroom calculates the tailroom and
    subtracts this value by reserved_tailroom. However
    reserved_tailroom is a union with the skb mark. This means
    that we subtract the tailroom by the skb mark if set.
    Fix this by using skb_tailroom instead.

    Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible")
    Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible")
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • We allocate the page fragment for the ESP trailer inside
    a spinlock, but consume it outside of the lock. This
    is racy as some other cou could get the same page fragment
    then. Fix this by consuming the page fragment inside the
    lock too.

    Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible")
    Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible")
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

02 Aug, 2017

2 commits

  • Both ip6_input_finish (non-GRO) and esp6_gro_receive (GRO) strip
    the IPv6 header without adjusting skb->csum accordingly. As a
    result CHECKSUM_COMPLETE breaks and "hw csum failure" is written
    to the kernel log by netdev_rx_csum_fault (dev.c).

    Fix skb->csum by substracting the checksum value of the pulled IPv6
    header using a call to skb_postpull_rcsum.

    This affects both transport and tunnel modes.

    Note that the fix occurs far from the place that the header was
    pulled. This is based on existing code, see:
    ipv6_srh_rcv() in exthdrs.c and rawv6_rcv() in raw.c

    Signed-off-by: Yossi Kuperman
    Signed-off-by: Ilan Tayari
    Signed-off-by: Steffen Klassert

    Yossi Kuperman
     
  • Keep the device's reported ip_summed indication in case crypto
    was offloaded by the device. Subtract the csum values of the
    stripped parts (esp header+iv, esp trailer+auth_data) to keep
    value correct.

    Note: CHECKSUM_COMPLETE should be indicated only if skb->csum
    has the post-decryption offload csum value.

    Signed-off-by: Ariel Levkovich
    Signed-off-by: Ilan Tayari
    Signed-off-by: Steffen Klassert

    Ilan Tayari
     

13 Jul, 2017

1 commit

  • We leak the temporary allocated resources in error paths,
    fix this by freeing them.

    Fixes: fca11ebde3f ("esp4: Reorganize esp_output")
    Fixes: 383d0350f2c ("esp6: Reorganize esp_output")
    Fixes: 3f29770723f ("ipsec: check return value of skb_to_sgvec always")
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

01 Jul, 2017

1 commit

  • refcount_t type and corresponding API should be
    used instead of atomic_t when the variable is used as
    a reference counter. This allows to avoid accidental
    refcounter overflows that might lead to use-after-free
    situations.

    Signed-off-by: Elena Reshetova
    Signed-off-by: Hans Liljestrand
    Signed-off-by: Kees Cook
    Signed-off-by: David Windsor
    Signed-off-by: David S. Miller

    Reshetova, Elena
     

24 Jun, 2017

1 commit

  • Steffen Klassert says:

    ====================
    pull request (net-next): ipsec-next 2017-06-23

    1) Use memdup_user to spmlify xfrm_user_policy.
    From Geliang Tang.

    2) Make xfrm_dev_register static to silence a sparse warning.
    From Wei Yongjun.

    3) Use crypto_memneq to check the ICV in the AH protocol.
    From Sabrina Dubroca.

    4) Remove some unused variables in esp6.
    From Stephen Hemminger.

    5) Extend XFRM MIGRATE to allow to change the UDP encapsulation port.
    From Antony Antony.

    6) Include the UDP encapsulation port to km_migrate announcements.
    From Antony Antony.

    Please pull or let me know if there are problems.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

16 Jun, 2017

1 commit

  • It seems like a historic accident that these return unsigned char *,
    and in many places that means casts are required, more often than not.

    Make these functions return void * and remove all the casts across
    the tree, adding a (u8 *) cast only where the unsigned char pointer
    was used directly, all done with the following spatch:

    @@
    expression SKB, LEN;
    typedef u8;
    identifier fn = { skb_push, __skb_push, skb_push_rcsum };
    @@
    - *(fn(SKB, LEN))
    + *(u8 *)fn(SKB, LEN)

    @@
    expression E, SKB, LEN;
    identifier fn = { skb_push, __skb_push, skb_push_rcsum };
    type T;
    @@
    - E = ((T *)(fn(SKB, LEN)))
    + E = fn(SKB, LEN)

    @@
    expression SKB, LEN;
    identifier fn = { skb_push, __skb_push, skb_push_rcsum };
    @@
    - fn(SKB, LEN)[0]
    + *(u8 *)fn(SKB, LEN)

    Note that the last part there converts from push(...)[0] to the
    more idiomatic *(u8 *)push(...).

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

05 Jun, 2017

1 commit


22 May, 2017

1 commit

  • Resolves warnings:
    net/ipv6/esp6.c: In function ‘esp_ssg_unref’:
    net/ipv6/esp6.c:121:10: warning: variable ‘seqhi’ set but not used [-Wunused-but-set-variable]
    net/ipv6/esp6.c: In function ‘esp6_output_head’:
    net/ipv6/esp6.c:227:21: warning: variable ‘esph’ set but not used [-Wunused-but-set-variable]

    Signed-off-by: Stephen Hemminger
    Signed-off-by: Steffen Klassert

    Stephen Hemminger
     

24 Apr, 2017

1 commit

  • A recent commit moved esp_alloc_tmp() out of a lock
    protected region, but forgot to remove the unlock from
    the error path. This patch removes the forgotten unlock.
    While at it, remove some unneeded error assignments too.

    Fixes: fca11ebde3f0 ("esp4: Reorganize esp_output")
    Fixes: 383d0350f2cc ("esp6: Reorganize esp_output")
    Reported-by: Dan Carpenter
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

14 Apr, 2017

5 commits

  • We need a fallback algorithm for crypto offloading to a NIC.
    This is because packets can be rerouted to other NICs that
    don't support crypto offloading. The fallback is going to be
    implemented at layer2 where we know the final output device
    but can't handle asynchronous returns fron the crypto layer.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • This patch extends the xfrm_type by an encap function pointer
    and implements esp4_gso_encap and esp6_gso_encap. These functions
    doing the basic esp encapsulation for a GSO packet. In case the
    GSO packet needs to be segmented in software, we add gso_segment
    functions. This codepath is going to be used on esp hardware
    offloads.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • We need a fallback for ESP at layer 2, so split esp6_output
    into generic functions that can be used at layer 3 and layer 2
    and use them in esp_output. We also add esp6_xmit which is
    used for the layer 2 fallback.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • We are going to export the ipv4 and the ipv6
    version of esp_input_done2. They are not static
    anymore and can't have the same name. So rename
    the ipv6 version to esp6_input_done2.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • This patch adds all the bits that are needed to do
    IPsec hardware offload for IPsec states and ESP packets.
    We add xfrmdev_ops to the net_device. xfrmdev_ops has
    function pointers that are needed to manage the xfrm
    states in the hardware and to do a per packet
    offloading decision.

    Joint work with:
    Ilan Tayari
    Guy Shapiro
    Yossi Kuperman

    Signed-off-by: Guy Shapiro
    Signed-off-by: Ilan Tayari
    Signed-off-by: Yossi Kuperman
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

17 Jan, 2017

2 commits

  • We need to setup the trailer in two different cases,
    so add a helper to avoid code duplication.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     
  • This patch tries to avoid skb_cow_data on esp6.

    On the encrypt side we add the IPsec tailbits
    to the linear part of the buffer if there is
    space on it. If there is no space on the linear
    part, we add a page fragment with the tailbits to
    the buffer and use separate src and dst scatterlists.

    On the decrypt side, we leave the buffer as it is
    if it is not cloned.

    With this, we can avoid a linearization of the buffer
    in most of the cases.

    Joint work with:
    Sowmini Varadhan
    Ilan Tayari

    Signed-off-by: Sowmini Varadhan
    Signed-off-by: Ilan Tayari
    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

04 Dec, 2016

1 commit

  • Couple conflicts resolved here:

    1) In the MACB driver, a bug fix to properly initialize the
    RX tail pointer properly overlapped with some changes
    to support variable sized rings.

    2) In XGBE we had a "CONFIG_PM" --> "CONFIG_PM_SLEEP" fix
    overlapping with a reorganization of the driver to support
    ACPI, OF, as well as PCI variants of the chip.

    3) In 'net' we had several probe error path bug fixes to the
    stmmac driver, meanwhile a lot of this code was cleaned up
    and reorganized in 'net-next'.

    4) The cls_flower classifier obtained a helper function in
    'net-next' called __fl_delete() and this overlapped with
    Daniel Borkamann's bug fix to use RCU for object destruction
    in 'net'. It also overlapped with Jiri's change to guard
    the rhashtable_remove_fast() call with a check against
    tc_skip_sw().

    5) In mlx4, a revert bug fix in 'net' overlapped with some
    unrelated changes in 'net-next'.

    6) In geneve, a stale header pointer after pskb_expand_head()
    bug fix in 'net' overlapped with a large reorganization of
    the same code in 'net-next'. Since the 'net-next' code no
    longer had the bug in question, there was nothing to do
    other than to simply take the 'net-next' hunks.

    Signed-off-by: David S. Miller

    David S. Miller
     

30 Nov, 2016

1 commit


05 Nov, 2016

1 commit

  • - Use the UID in routing lookups made by protocol connect() and
    sendmsg() functions.
    - Make sure that routing lookups triggered by incoming packets
    (e.g., Path MTU discovery) take the UID of the socket into
    account.
    - For packets not associated with a userspace socket, (e.g., ping
    replies) use UID 0 inside the user namespace corresponding to
    the network namespace the socket belongs to. This allows
    all namespaces to apply routing and iptables rules to
    kernel-originated traffic in that namespaces by matching UID 0.
    This is better than using the UID of the kernel socket that is
    sending the traffic, because the UID of kernel sockets created
    at namespace creation time (e.g., the per-processor ICMP and
    TCP sockets) is the UID of the user that created the socket,
    which might not be mapped in the namespace.

    Tested: compiles allnoconfig, allyesconfig, allmodconfig
    Tested: https://android-review.googlesource.com/253302
    Signed-off-by: Lorenzo Colitti
    Signed-off-by: David S. Miller

    Lorenzo Colitti
     

28 May, 2015

1 commit

  • This patch makes use of the new AEAD interface which uses a single
    SG list instead of separate lists for the AD and plain text. The
    IV generation is also now carried out through normal AEAD methods.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

01 Apr, 2015

1 commit

  • The ipv6 code uses a mixture of coding styles. In some instances check for NULL
    pointer is done as x == NULL and sometimes as !x. !x is preferred according to
    checkpatch and this patch makes the code consistent by adopting the latter
    form.

    No changes detected by objdiff.

    Signed-off-by: Ian Morris
    Signed-off-by: David S. Miller

    Ian Morris
     

24 Nov, 2014

1 commit


12 Nov, 2014

1 commit

  • Use the more common dynamic_debug capable net_dbg_ratelimited
    and remove the LIMIT_NETDEBUG macro.

    All messages are still ratelimited.

    Some KERN_ uses are changed to KERN_DEBUG.

    This may have some negative impact on messages that were
    emitted at KERN_INFO that are not not enabled at all unless
    DEBUG is defined or dynamic_debug is enabled. Even so,
    these messages are now _not_ emitted by default.

    This also eliminates the use of the net_msg_warn sysctl
    "/proc/sys/net/core/warnings". For backward compatibility,
    the sysctl is not removed, but it has no function. The extern
    declaration of net_msg_warn is removed from sock.h and made
    static in net/core/sysctl_net_core.c

    Miscellanea:

    o Update the sysctl documentation
    o Remove the embedded uses of pr_fmt
    o Coalesce format fragments
    o Realign arguments

    Signed-off-by: Joe Perches
    Signed-off-by: David S. Miller

    Joe Perches
     

07 Nov, 2014

1 commit

  • Commit 64ce207306de ("[NET]: Make NETDEBUG pure printk wrappers")
    originally had these NETDEBUG printks as always emitting.

    Commit a2a316fd068c ("[NET]: Replace CONFIG_NET_DEBUG with sysctl")
    added a net_msg_warn sysctl to these NETDEBUG uses.

    Convert these NETDEBUG uses to normal pr_info calls.

    This changes the output prefix from "ESP: " to include
    "IPSec: " for the ipv4 case and "IPv6: " for the ipv6 case.

    These output lines are now like the other messages in the files.

    Other miscellanea:

    Neaten the arithmetic spacing to be consistent with other
    arithmetic spacing in the files.

    Signed-off-by: Joe Perches
    Signed-off-by: David S. Miller

    Joe Perches
     

25 Aug, 2014

2 commits

  • This patch makes no changes to the logic of the code but simply addresses
    coding style issues as detected by checkpatch.

    Both objdump and diff -w show no differences.

    This patch addresses structure definitions, specifically it cleanses the brace
    placement and replaces spaces with tabs in a few places.

    Signed-off-by: Ian Morris
    Signed-off-by: David S. Miller

    Ian Morris
     
  • This patch makes no changes to the logic of the code but simply addresses
    coding style issues as detected by checkpatch.

    Both objdump and diff -w show no differences.

    A number of items are addressed in this patch:
    * Multiple spaces converted to tabs
    * Spaces before tabs removed.
    * Spaces in pointer typing cleansed (char *)foo etc.
    * Remove space after sizeof
    * Ensure spacing around comparators such as if statements.

    Signed-off-by: Ian Morris
    Signed-off-by: David S. Miller

    Ian Morris
     

14 Mar, 2014

1 commit


07 Dec, 2013

1 commit

  • Several files refer to an old address for the Free Software Foundation
    in the file header comment. Resolve by replacing the address with
    the URL so that we do not have to keep
    updating the header comments anytime the address changes.

    CC: Alexey Kuznetsov
    CC: James Morris
    CC: Hideaki YOSHIFUJI
    CC: Patrick McHardy
    Signed-off-by: Jeff Kirsher
    Signed-off-by: David S. Miller

    Jeff Kirsher
     

02 Nov, 2013

1 commit


29 Oct, 2013

2 commits


16 Sep, 2013

1 commit

  • Currently we update the pmtu in the IPsec protocol error handlers
    if icmpv6 message type is either ICMPV6_DEST_UNREACH or
    ICMPV6_PKT_TOOBIG. Updating the pmtu on ICMPV6_DEST_UNREACH
    is wrong in any case, it causes strangely fragmented packets.
    Only ICMPV6_PKT_TOOBIG signalizes pmtu discovery, so remove the
    ICMPV6_DEST_UNREACH check in the IPsec protocol error handlers.

    Signed-off-by: Steffen Klassert

    Steffen Klassert
     

06 Sep, 2013

1 commit

  • RFC 4861 says that the IP source address of the Redirect is the
    same as the current first-hop router for the specified ICMP
    Destination Address, so the gateway should be taken into
    consideration when we find the route for redirect.

    There was once a check in commit
    a6279458c534d01ccc39498aba61c93083ee0372 ("NDISC: Search over
    all possible rules on receipt of redirect.") and the check
    went away in commit b94f1c0904da9b8bf031667afc48080ba7c3e8c9
    ("ipv6: Use icmpv6_notify() to propagate redirect, instead of
    rt6_redirect()").

    The bug is only "exploitable" on layer-2 because the source
    address of the redirect is checked to be a valid link-local
    address but it makes spoofing a lot easier in the same L2
    domain nonetheless.

    Thanks very much for Hannes's help.

    Signed-off-by: Duan Jiong
    Acked-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Duan Jiong
     

06 Aug, 2013

1 commit

  • Commit 91657eafb ("xfrm: take net hdr len into account for esp payload
    size calculation") introduced a possible interger overflow in
    esp{4,6}_get_mtu() handlers in case of x->props.mode equals
    XFRM_MODE_TUNNEL. Thus, the following expression will overflow

    unsigned int net_adj;
    ...

    net_adj = 0;
    ...
    return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
    net_adj) & ~(align - 1)) + (net_adj - 2);

    where (net_adj - 2) would be evaluated as + (0 - 2) in an unsigned
    context. Fix it by simply removing brackets as those operations here
    do not need to have special precedence.

    Signed-off-by: Daniel Borkmann
    Cc: Benjamin Poirier
    Cc: Steffen Klassert
    Acked-by: Benjamin Poirier
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

08 Jan, 2013

1 commit

  • IPsec tunnel does not set ECN field to CE in inner header when
    the ECN field in the outer header is CE, and the ECN field in
    the inner header is ECT(0) or ECT(1).

    The cause is ipip6_hdr() does not return the correct address of
    inner header since skb->transport-header is not the inner header
    after esp6_input_done2(), or ah6_input().

    Signed-off-by: Li RongQing
    Signed-off-by: Steffen Klassert

    Li RongQing