• Tom Parkin's avatar
    l2tp: make magic feather checks more useful · 45faeff1
    Tom Parkin authored
    The l2tp tunnel and session structures contain a "magic feather" field
    which was originally intended to help trace lifetime bugs in the code.
    
    Since the introduction of the shared kernel refcount code in refcount.h,
    and l2tp's porting to those APIs, we are covered by the refcount code's
    checks and warnings.  Duplicating those checks in the l2tp code isn't
    useful.
    
    However, magic feather checks are still useful to help to detect bugs
    stemming from misuse/trampling of the sk_user_data pointer in struct
    sock.  The l2tp code makes extensive use of sk_user_data to stash
    pointers to the tunnel and session structures, and if another subsystem
    overwrites sk_user_data it's important to detect this.
    
    As such, rework l2tp's magic feather checks to focus on validating the
    tunnel and session data structures when they're extracted from
    sk_user_data.
    
     * Add a new accessor function l2tp_sk_to_tunnel which contains a magic
       feather check, and is used by l2tp_core and l2tp_ip[6]
     * Comment l2tp_udp_encap_recv which doesn't use this new accessor function
       because of the specific nature of the codepath it is called in
     * Drop l2tp_session_queue_purge's check on the session magic feather:
       it is called from code which is walking the tunnel session list, and
       hence doesn't need validation
     * Drop l2tp_session_free's check on the tunnel magic feather: the
       intention of this check is covered by refcount.h's reference count
       sanity checking
     * Add session magic validation in pppol2tp_ioctl.  On failure return
       -EBADF, which mirrors the approach in pppol2tp_[sg]etsockopt.
    Signed-off-by: default avatarTom Parkin <tparkin@katalix.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    45faeff1
l2tp_ip6.c 19.2 KB