Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3493304pxf; Mon, 29 Mar 2021 03:56:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1NhTHmm7t8vQ5bg4TpiM8x/nXrVkOIa3zJUUgwc0wUTG1wvrLkIVDinrX8rciAbVlmsB1 X-Received: by 2002:a17:906:aed6:: with SMTP id me22mr28190230ejb.146.1617015411729; Mon, 29 Mar 2021 03:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617015411; cv=none; d=google.com; s=arc-20160816; b=O8z3VfrXprnayTtn46DCeoU2rWC6KwQKEbhpX8B/CtH1eknhhpqlIs9FWYcAR5uoC6 O4J1DY2Z2SLn6wyeFPCPI6UY+1GNnrgwoqvi7YOhxooJJQo3cbJC4Mx94x8P3fNhGhdA AgIzyyIwynwadmjAoGvLXaS3WOynTKwTDLeMrS3ZuiGs2vnec89Pc44LnZ8c5T9fhPU/ S0Fn8WjK8sjAEZtpngjeowT8MQ9wvzYR9IdjO4wwu5Bt7bgY08zTz/k5UV/50ys3QqHW /+0r6yfGpec0kwgWdY8Ffq4HCuAAvFaCsE7i9UWHbebn2Fwa6UuA4yo23BZZwPTHCruG wl8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AAwwjjBT8VY8xt6Ttnqok9rjl/Ir5pkUj2VX/UlnBlc=; b=d8M58ZnBYwZ9HL/NI2O/61c0B3RYEbstGy27xzM8cHEWPdqQfMr5kJVd/g5LSEPvzT xtXsr8jXHrD6BfGV9Ojb/OWtOBU5++NctuJ2uZtSjfvEGLAc62ve7cPyCDrgI7WEuH9j jhaNzwnvjclET+3BP9ExdRcmdOfGyF9FVvcxI5ODKCewL/i43Wti9xXRJYVQYDEZjFcO 1a8LPaqLOIVTkTRfQiwZUHYDBgWjqiT2O5MX62VnHsJY7DoUNnNIdB5R/4blRWq0Udqp Zc43uozlRg3ENvvrAxdFBokI4ImFK61pMDnwQxFbr9OninzpNkvd1VuH5l9wRsUjXLH6 2Ayg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kGT9m5La; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si13143221edp.256.2021.03.29.03.56.29; Mon, 29 Mar 2021 03:56:51 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=kGT9m5La; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235715AbhC2Ird (ORCPT + 99 others); Mon, 29 Mar 2021 04:47:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233704AbhC2I0V (ORCPT ); Mon, 29 Mar 2021 04:26:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 949F4619AB; Mon, 29 Mar 2021 08:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006343; bh=yjv2LKnsY9U0sg39vJh2PawardPbcyh+L50I0kzsIvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kGT9m5LafnLIW7jhzwxcepu6XQEbzezFZ1OoDueFJkZbFGx2FrjHacOG5p1BGaSgx 1DNy2ZdtnKJ+8QFWBt/tc1Q52Co75EhVAP409HVEyfT5VqvKWLL66LhO/C9nlQgv58 CxGslN7b0+dDpLqoEzvOGRcZxWLK5OujOld1AZCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yonghong Song , Alexei Starovoitov , Roman Gushchin , Sasha Levin Subject: [PATCH 5.10 179/221] bpf: Dont do bpf_cgroup_storage_set() for kuprobe/tp programs Date: Mon, 29 Mar 2021 09:58:30 +0200 Message-Id: <20210329075635.121265630@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 05a68ce5fa51a83c360381630f823545c5757aa2 ] For kuprobe and tracepoint bpf programs, kernel calls trace_call_bpf() which calls BPF_PROG_RUN_ARRAY_CHECK() to run the program array. Currently, BPF_PROG_RUN_ARRAY_CHECK() also calls bpf_cgroup_storage_set() to set percpu cgroup local storage with NULL value. This is due to Commit 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage") which modified __BPF_PROG_RUN_ARRAY() to call bpf_cgroup_storage_set() and this macro is also used by BPF_PROG_RUN_ARRAY_CHECK(). kuprobe and tracepoint programs are not allowed to call bpf_get_local_storage() helper hence does not access percpu cgroup local storage. Let us change BPF_PROG_RUN_ARRAY_CHECK() not to modify percpu cgroup local storage. The issue is observed when I tried to debug [1] where percpu data is overwritten due to preempt_disable -> migration_disable change. This patch does not completely fix the above issue, which will be addressed separately, e.g., multiple cgroup prog runs may preempt each other. But it does fix any potential issue caused by tracing program overwriting percpu cgroup storage: - in a busy system, a tracing program is to run between bpf_cgroup_storage_set() and the cgroup prog run. - a kprobe program is triggered by a helper in cgroup prog before bpf_get_local_storage() is called. [1] https://lore.kernel.org/bpf/CAKH8qBuXCfUz=w8L+Fj74OaUpbosO29niYwTki7e3Ag044_aww@mail.gmail.com/T Fixes: 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage") Signed-off-by: Yonghong Song Signed-off-by: Alexei Starovoitov Acked-by: Roman Gushchin Link: https://lore.kernel.org/bpf/20210309185028.3763817-1-yhs@fb.com Signed-off-by: Sasha Levin --- include/linux/bpf.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 76322b6452c8..dd236ef59db3 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1059,7 +1059,7 @@ int bpf_prog_array_copy(struct bpf_prog_array *old_array, struct bpf_prog *include_prog, struct bpf_prog_array **new_array); -#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null) \ +#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null, set_cg_storage) \ ({ \ struct bpf_prog_array_item *_item; \ struct bpf_prog *_prog; \ @@ -1072,7 +1072,8 @@ int bpf_prog_array_copy(struct bpf_prog_array *old_array, goto _out; \ _item = &_array->items[0]; \ while ((_prog = READ_ONCE(_item->prog))) { \ - bpf_cgroup_storage_set(_item->cgroup_storage); \ + if (set_cg_storage) \ + bpf_cgroup_storage_set(_item->cgroup_storage); \ _ret &= func(_prog, ctx); \ _item++; \ } \ @@ -1133,10 +1134,10 @@ _out: \ }) #define BPF_PROG_RUN_ARRAY(array, ctx, func) \ - __BPF_PROG_RUN_ARRAY(array, ctx, func, false) + __BPF_PROG_RUN_ARRAY(array, ctx, func, false, true) #define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func) \ - __BPF_PROG_RUN_ARRAY(array, ctx, func, true) + __BPF_PROG_RUN_ARRAY(array, ctx, func, true, false) #ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU(int, bpf_prog_active); -- 2.30.1