Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp504787pxu; Wed, 25 Nov 2020 08:28:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4FnBHqk2N7kye4L8eGzve39TAgkkPR4NEgG2XnmocQGdMug7tav+xVMtQh0QDqqf7UCVi X-Received: by 2002:a17:906:8541:: with SMTP id h1mr3668988ejy.445.1606321714234; Wed, 25 Nov 2020 08:28:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606321714; cv=none; d=google.com; s=arc-20160816; b=HJuagZQtvlHr1lHEc9rMviInjsWylikl+RpJ0r0RISB+tTFuSJX/Cvs55ryC6rcebH E+16jJhAUvuqu81Z+kUyS6p5wWfkAVDrh9vOhZeG+S+2H2LWiPFhH6mZsl9S6PWKMlMS WdzBs19IGUNlR1qUSnhkkOyjuFK9rfsFuJvbNVUjDGeIx6wTWYh/Q0MByOZfK43f7mGS hVCfQKWet9H9YPic5WTRRCZcvESf9o6OCMTg0xUTKI8TnlWz+o+vNc+o3wR7au3/7nKl rWl/fLuikdfRUkb+wiGgiWkV9nFFyu5/CwqtB2O+zh8SepKur739AHOUX4JxnvmSmKS3 MMBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=8MW/chtXMDHQuBOgmTsYPh05am1GlhIQ+niX5dI50VM=; b=gcJloeDjUOr+UhXzncrb0ve7GHrcyF7bYMaw6DppwrZ4KNFt/5ORVX6+FJixg1ea0y yDBZJV9y5HKHLkMf78z3mxJZE/yNC/MucCVrlMrh/XoEs922bykWewkVHLZzWMLj9sTj xjzYCHyrB5AtFOb/vVGRUjubOOB85ThqEBXphyB01bQSxZ4wk8cB8tAxT0NtTQ5JzhXp q4KZiIKQhMO6pVHtO9GDcu0YJ51Qg7/IGzbvC4OSXEW0X8TRST61gAPFj4Vrt3xdhCzd RZ2mps12/tQtNt0+PK4KyXabZqzLM3jAb0NyHSg+AZUgVXWBq+ERYbr87ew6jDKR/JVs kmEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eFXlKdUK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f24si1462822edw.120.2020.11.25.08.28.11; Wed, 25 Nov 2020 08:28:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eFXlKdUK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731364AbgKYQZh (ORCPT + 99 others); Wed, 25 Nov 2020 11:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730835AbgKYQZh (ORCPT ); Wed, 25 Nov 2020 11:25:37 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C5ADC0613D4 for ; Wed, 25 Nov 2020 08:25:37 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id d206so2890843qkc.23 for ; Wed, 25 Nov 2020 08:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=8MW/chtXMDHQuBOgmTsYPh05am1GlhIQ+niX5dI50VM=; b=eFXlKdUKA/vjcLYDGy2YZypDYWN0dgy0Y6A4XyQsPrfX2awkMNy6GC8/qz5jXr/RbX 4kqY5wdBcTbby7EUyLssjlseLlDvWoKqNKmiG+aWlJuXxI2wl766v2coEgAXLXjUe8zX hXiOK99HBJ5eZ86ZpKO3jfPctTPDEvs/A6A703q2lrIHr07lxW2FjZu/Vw7h8XC57xf7 ddI9JaRsPJv8Cbq7LGVe3VJr7VELWBfEIpHoHbtbKnGQNv/jWnykRYWNU0fIE8+hRc9e jzby0pb9dy041+Iirv35fTN+OzEJUrfhUgAlJ1S9rOldcWisemLLaDBOuH8km1jO2DMj vFxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8MW/chtXMDHQuBOgmTsYPh05am1GlhIQ+niX5dI50VM=; b=s7Uka86HJ+uF4uQ1KN8mKM3GM+Us79bkaHXxYTw5ryseMGVGeGgcT7CJtyox1l/7R8 sYtHPPntx/lOXhigO3V3BNslc+Kp8MxqjdLUaLnHVDqEG23rHX1f2tEet7gouN2g4v8V wq7GMOTZ2KqXbiuMOKrIUu+znCuhwaVn2D4hlkzOxwbNQSXoXfoXTLLkje/UaI+DES+Y O23OvAJsFSm35EdH8h1rzbeicnljTMJMOLQMwuw/Wv69pmZ7+thz1Jyj9Uf9tWC5tC6A Zo/2BzX3jiW5uo9L0D1NIphkhn153wuo5wQymdU7vqe73sH5XlJiDUB3eVG3NkxGGhFH Djpw== X-Gm-Message-State: AOAM530kuwd5tMumNfsyphfrjD6Ndc3Hg10qnBEVDKTvmIrveHC4TCw4 RowbO6P/UHJ0aS6R5xj4dfKSMfC08Q== Sender: "elver via sendgmr" X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) (user=elver job=sendgmr) by 2002:a0c:a802:: with SMTP id w2mr2490859qva.9.1606321536477; Wed, 25 Nov 2020 08:25:36 -0800 (PST) Date: Wed, 25 Nov 2020 17:24:54 +0100 In-Reply-To: <20201125162455.1690502-1-elver@google.com> Message-Id: <20201125162455.1690502-3-elver@google.com> Mime-Version: 1.0 References: <20201125162455.1690502-1-elver@google.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v6 2/3] net: store KCOV remote handle in sk_buff From: Marco Elver To: elver@google.com, davem@davemloft.net, kuba@kernel.org, johannes@sipsolutions.net Cc: akpm@linux-foundation.org, a.nogikh@gmail.com, edumazet@google.com, andreyknvl@google.com, dvyukov@google.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, idosch@idosch.org, fw@strlen.de, willemb@google.com, Aleksandr Nogikh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aleksandr Nogikh Remote KCOV coverage collection enables coverage-guided fuzzing of the code that is not reachable during normal system call execution. It is especially helpful for fuzzing networking subsystems, where it is common to perform packet handling in separate work queues even for the packets that originated directly from the user space. More details can be found in Documentation/dev-tools/kcov.rst. Enable coverage-guided frame injection by adding a kcov_handle parameter to sk_buff structure. Initializate this field in __alloc_skb to kcov_common_handle() so that no socket buffer that was generated during a system call is missed. For sk_buffs that were allocated in an interrupt context, kcov_handle will be initialized to 0. Code that is of interest and that performs packet processing should be annotated with kcov_remote_start()/kcov_remote_stop(). An alternative approach is to determine kcov_handle solely on the basis of the device/interface that received the specific socket buffer. However, in this case it would be impossible to distinguish between packets that originated from normal background network processes and those that were intentionally injected from the user space. Signed-off-by: Aleksandr Nogikh Signed-off-by: Marco Elver --- v6: * Revert usage of skb extensions in favour of directly storing the kcov_handle in in sk_buff. skb extensions were leading to a memory leak as reported by Ido Schimmel: https://lore.kernel.org/linux-wireless/20201121160941.GA485907@shredder.lan/ --- include/linux/skbuff.h | 21 +++++++++++++++++++++ net/core/skbuff.c | 1 + 2 files changed, 22 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a828cf99c521..5639f27e05ef 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -701,6 +701,7 @@ typedef unsigned char *sk_buff_data_t; * @transport_header: Transport layer header * @network_header: Network layer header * @mac_header: Link layer header + * @kcov_handle: KCOV remote handle for remote coverage collection * @tail: Tail pointer * @end: End pointer * @head: Head of buffer @@ -904,6 +905,10 @@ struct sk_buff { __u16 network_header; __u16 mac_header; +#ifdef CONFIG_KCOV + u64 kcov_handle; +#endif + /* private: */ __u32 headers_end[0]; /* public: */ @@ -4605,5 +4610,21 @@ static inline void skb_reset_redirect(struct sk_buff *skb) #endif } +static inline void skb_set_kcov_handle(struct sk_buff *skb, const u64 kcov_handle) +{ +#ifdef CONFIG_KCOV + skb->kcov_handle = kcov_handle; +#endif +} + +static inline u64 skb_get_kcov_handle(struct sk_buff *skb) +{ +#ifdef CONFIG_KCOV + return skb->kcov_handle; +#else + return 0; +#endif +} + #endif /* __KERNEL__ */ #endif /* _LINUX_SKBUFF_H */ diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1ba8f0163744..2f27635c3e97 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -233,6 +233,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, skb->end = skb->tail + size; skb->mac_header = (typeof(skb->mac_header))~0U; skb->transport_header = (typeof(skb->transport_header))~0U; + skb_set_kcov_handle(skb, kcov_common_handle()); /* make sure we initialize shinfo sequentially */ shinfo = skb_shinfo(skb); -- 2.29.2.454.gaff20da3a2-goog