#endif /* CONFIG_INET */
 }
 
+/* This helper checks if a socket is a full socket,
+ * ie _not_ a timewait or request socket.
+ */
+static inline bool sk_fullsock(const struct sock *sk)
+{
+       return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV);
+}
+
+static inline bool
+sk_is_refcounted(struct sock *sk)
+{
+       /* Only full sockets have sk->sk_flags. */
+       return !sk_fullsock(sk) || !sock_flag(sk, SOCK_RCU_FREE);
+}
+
 /**
  * skb_steal_sock
  * @skb to steal the socket from
                struct sock *sk = skb->sk;
 
                *refcounted = true;
+               if (skb_sk_is_prefetched(skb))
+                       *refcounted = sk_is_refcounted(sk);
                skb->destructor = NULL;
                skb->sk = NULL;
                return sk;
        return NULL;
 }
 
-/* This helper checks if a socket is a full socket,
- * ie _not_ a timewait or request socket.
- */
-static inline bool sk_fullsock(const struct sock *sk)
-{
-       return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV);
-}
-
 /* Checks if this SKB belongs to an HW offloaded socket
  * and whether any SW fallbacks are required based on dev.
  * Check decrypted mark in case skb_orphan() cleared socket.
 
 
 BPF_CALL_1(bpf_sk_release, struct sock *, sk)
 {
-       /* Only full sockets have sk->sk_flags. */
-       if (!sk_fullsock(sk) || !sock_flag(sk, SOCK_RCU_FREE))
+       if (sk_is_refcounted(sk))
                sock_gen_put(sk);
        return 0;
 }
                return -ENETUNREACH;
        if (unlikely(sk->sk_reuseport))
                return -ESOCKTNOSUPPORT;
-       if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
+       if (sk_is_refcounted(sk) &&
+           unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
                return -ENOENT;
 
        skb_orphan(skb);
 
 #ifdef CONFIG_INET
 void sock_pfree(struct sk_buff *skb)
 {
-       sock_gen_put(skb->sk);
+       if (sk_is_refcounted(skb->sk))
+               sock_gen_put(skb->sk);
 }
 EXPORT_SYMBOL(sock_pfree);
 #endif /* CONFIG_INET */