From patchwork Fri Mar 19 03:12:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 12149881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C00CC433DB for ; Fri, 19 Mar 2021 03:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C5BA64EB3 for ; Fri, 19 Mar 2021 03:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233466AbhCSDMz (ORCPT ); Thu, 18 Mar 2021 23:12:55 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:23750 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231297AbhCSDMj (ORCPT ); Thu, 18 Mar 2021 23:12:39 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.43/8.16.0.43) with SMTP id 12J3AXN8006759 for ; Thu, 18 Mar 2021 20:12:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=facebook; bh=ThR/y2rsSmVT1jVbDSe6H/o1lThx3vDWph2btY+dqGs=; b=OaXCBx5GF9tJus6AWOTlixEfsC6bjR+46K005F3Q3Xp+rNQ1uLPSRD7eO24EHXx7GXaD EeGXXxiVtFMSxMTO3w9rHZNWHja9w3nxpBVqbr0Mmp/jJIVulolm2uVcXpW3hFB4188U AK+Sft08hSFZdNHsk7NF4JULWKx7Lq75sUU= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 37bs1h8d5g-14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 18 Mar 2021 20:12:38 -0700 Received: from intmgw002.06.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 18 Mar 2021 20:12:38 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 7B95E7A9D3B; Thu, 18 Mar 2021 20:12:31 -0700 (PDT) From: Yonghong Song To: CC: Alexei Starovoitov , Daniel Borkmann , Subject: [PATCH bpf-next v2 0/2] bpf: fix NULL pointer dereference in Date: Thu, 18 Mar 2021 20:12:31 -0700 Message-ID: <20210319031231.3707705-1-yhs@fb.com> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-18_19:2021-03-17,2021-03-18 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=421 bulkscore=0 priorityscore=1501 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103190022 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Jiri Olsa reported a bug in https://lore.kernel.org/bpf/CAKH8qBuXCfUz=w8L+Fj74OaUpbosO29niYwTki7e3Ag044_aww@mail.gmail.com/T where cgroup local storage pointer may be NULL in bpf_get_local_storage() helper. There are two issues uncovered by this bug: (1). kprobe or tracepoint prog incorrectly sets cgroup local storage before prog run, (2). due to change from preempt_disable to migrate_disable, preemption is possible and percpu storage might be overwritten by other tasks. Issue (1) has been fixed and this patch set fixed issue (2). Please see details of Patch #1 for detailed fix. Patch #2 fixed bpf_prog_test_run to use new signature for bpf_cgroup_storage_set(). Patch #1 can be backported to bpf tree and Patch #2 cannot due to refactoring done in bpf-next only. I did not put a Fix tag as I am not able to find a proper one. The original commit which changed from preempt_disable to migrate_disable in bpf.h is just a wrapper where migrate_disable still calls preempt_disable. The real migrate_disable change happens later in kernel/sched/*. Changelogs: v1 -> v2: . fix compilation issues when CONFIG_CGROUPS is off or CONFIG_CGROUP_BPF is off. Yonghong Song (2): bpf: fix NULL pointer dereference in bpf_get_local_storage() helper bpf: fix bpf_cgroup_storage_set() usage in test_run include/linux/bpf-cgroup.h | 58 ++++++++++++++++++++++++++++++++------ include/linux/bpf.h | 22 ++++++++++++--- kernel/bpf/helpers.c | 15 +++++++--- kernel/bpf/local_storage.c | 5 ++-- net/bpf/test_run.c | 6 +++- 5 files changed, 87 insertions(+), 19 deletions(-)