Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2069418pxv; Sat, 26 Jun 2021 08:18:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1IVuUqhG0adZzL78FHYOMfvNvfzKvb5TBmscZZKO0reDhZC4czvJyqgTwf231w7U9hCQF X-Received: by 2002:a5d:8154:: with SMTP id f20mr13342245ioo.89.1624720739514; Sat, 26 Jun 2021 08:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624720739; cv=none; d=google.com; s=arc-20160816; b=JWB2KI76CfKz/mAmeYiViKqDVSJeaHUMFLLnVYReKsSQ2zusCmBdu4Ir+i+4VU7/he eCBl8cJpQ6IexuoeJbAHa2QJKNnIGruZPkBYJlKHcAWTZY1kGrN7tC0zV4vlgrX1Cb2G VRihEU2pfSUVY8aKAVeILLAIXd2mBV9z5QOxW9sU9jdJ0Le1clGQeVbdJ4HPsEQV928o njgCp6ZDsojpTPrL+j85gtAipN3LK0ZQUoZepIp+/S4eC5OJDApvm2OqUp9jyJUdKXSV Mr9oBnrZ9rIGvpdHR0Eyv1UrFTSu6nqKS2pu9BZ4MnwKJ4/TWVdewqj2cEovE0cKDzdu 0oVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject; bh=Uk6O1JrEqcL7TvnncZYdcpHe7AyTp4Fddbll/WrdG+Y=; b=lc68jSuu+0CdRs94cAliILlzQyV9u4SGarowAD7e8Ie7/CSyimWusjTFNn4XlBmtJr 69pyDc5wAua2PbrRDYvBhIL3RYDkU7cj15QTT3eEosUq6jlZd9fNjcGyW83fW2vDQXUW QqW7hBxmekg/xHVNdTDK/wrclKYL5p9Jg2iZaTAKjigcOdI7YYaqYpFPQSN0nMthxkrl HNGwTHKRYtgfF5Rw9t1c77WAH36CKdI6rcQaXIizOYwPaHxj48wAO2NgFyxljJiwJqfb aKoJBVb7RJUzDOIyL655A+WRNP7NhUCjyRMEPx1AYuQBtZFoxjeOiKvu1RLwthFJBwC4 jyHg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si11082840jaj.59.2021.06.26.08.18.47; Sat, 26 Jun 2021 08:18:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbhFZPUg (ORCPT + 99 others); Sat, 26 Jun 2021 11:20:36 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:55150 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbhFZPUe (ORCPT ); Sat, 26 Jun 2021 11:20:34 -0400 Received: from fsav118.sakura.ne.jp (fsav118.sakura.ne.jp [27.133.134.245]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 15QFHMSN075545; Sun, 27 Jun 2021 00:17:22 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav118.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav118.sakura.ne.jp); Sun, 27 Jun 2021 00:17:22 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav118.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 15QFHM6h075541 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 27 Jun 2021 00:17:22 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [PATCH] tracepoint: Do not warn on EEXIST or ENOENT From: Tetsuo Handa To: Steven Rostedt Cc: Peter Zijlstra , Mathieu Desnoyers , Ingo Molnar , Robert Richter , Gabriel Krisman Bertazi , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , netdev , bpf@vger.kernel.org References: <20210626135845.4080-1-penguin-kernel@I-love.SAKURA.ne.jp> <20210626101834.55b4ecf1@rorschach.local.home> <7297f336-70e5-82d3-f8d3-27f08c7d1548@i-love.sakura.ne.jp> Message-ID: Date: Sun, 27 Jun 2021 00:17:20 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <7297f336-70e5-82d3-f8d3-27f08c7d1548@i-love.sakura.ne.jp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/06/27 0:13, Tetsuo Handa wrote: > On 2021/06/26 23:18, Steven Rostedt wrote: >> On Sat, 26 Jun 2021 22:58:45 +0900 >> Tetsuo Handa wrote: >> >>> syzbot is hitting WARN_ON_ONCE() at tracepoint_add_func() [1], but >>> func_add() returning -EEXIST and func_remove() returning -ENOENT are >>> not kernel bugs that can justify crashing the system. >> >> There should be no path that registers a tracepoint twice. That's a bug >> in the kernel. Looking at the link below, I see the backtrace: >> >> Call Trace: >> tracepoint_probe_register_prio kernel/tracepoint.c:369 [inline] >> tracepoint_probe_register+0x9c/0xe0 kernel/tracepoint.c:389 >> __bpf_probe_register kernel/trace/bpf_trace.c:2154 [inline] >> bpf_probe_register+0x15a/0x1c0 kernel/trace/bpf_trace.c:2159 >> bpf_raw_tracepoint_open+0x34a/0x720 kernel/bpf/syscall.c:2878 >> __do_sys_bpf+0x2586/0x4f40 kernel/bpf/syscall.c:4435 >> do_syscall_64+0x3a/0xb0 arch/x86/entry/common.c:47 >> >> So BPF is allowing the user to register the same tracepoint more than >> once? That looks to be a bug in the BPF code where it shouldn't be >> allowing user space to register the same tracepoint multiple times. > > I didn't catch your question. > > (1) func_add() can reject an attempt to add same tracepoint multiple times > by returning -EINVAL to the caller. Sorry, s/EINVAL/EEXIST/g on (1) (2) (6). > (2) But tracepoint_add_func() (the caller of func_add()) is calling WARN_ON_ONCE() > if func_add() returned -EINVAL. > (3) And tracepoint_add_func() is triggerable via request from userspace. > (4) tracepoint_probe_register_prio() serializes tracepoint_add_func() call > triggered by concurrent request from userspace using tracepoints_mutex mutex. > (5) But tracepoint_add_func() does not check whether same tracepoint multiple > is already registered before calling func_add(). > (6) As a result, tracepoint_add_func() receives -EINVAL from func_add(), and > calls WARN_ON_ONCE() and the system crashes due to panic_on_warn == 1. > > Why this is a bug in the BPF code? The BPF code is not allowing userspace to > register the same tracepoint multiple times. I think that tracepoint_add_func() > is stupid enough to crash the kernel instead of rejecting when an attempt to > register the same tracepoint multiple times is made. >