Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3008302rwj; Mon, 19 Dec 2022 11:39:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6K8ZCyEsHvjLNvmDVZABorsseNnMNbeNQ+Qkh3syG6/UUfPrRs1db8xx/1kv1uG/B7CrkR X-Received: by 2002:a17:906:3604:b0:78d:f456:1ed0 with SMTP id q4-20020a170906360400b0078df4561ed0mr36715927ejb.33.1671478769095; Mon, 19 Dec 2022 11:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671478769; cv=none; d=google.com; s=arc-20160816; b=BonGE4ePYVDYBxolXttpEqxagE0FFtryvgKo4tHp2sZWp3MIYUtAx6e3SOsdTZXQqF BGd27o3QMLdJEDyMmfDIEdf/N7Ejdr/uOSTffpYQi9Q3v7GO24Ufd/+YhUst7llmG+Z0 f745Vt5JrZsdMZKzGy2ah6q9RQMDaHauh+fAWDcLjS2xskuHfbrm2aQk3P6OrE+c8LIa hwvibho8KIrNrJQHiJ8jmyHA7UKwXEFQzkxwwiLZhachnsNaoBucoLDVaP3Ipx5CLMCt r7w/UGrptwguB9sauWV1IwGKpkz6kMHEvZu83CkfbEPYraltirkh9rsBLAgo+mpYa2ez WC3Q== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=1BXl9vy0f2f/11VKxHLckXglqOMtK0anh34YjL4SpoA=; b=r3fmVAbH9+uI6eo+f2GxTLX5kqfYBpdYwJLxdWIVZVd5GD8h1SWomS/FJ00Bb+jEVY bJMskJ7GxvLPRJgFM44DfAqefWZbuPQhDAfUHi1HyixM98AZCnv5VElIOX3SCnt32y3q wmfCZwUI79m5YLQuspxd5MaSAkWpGSi4kjVzpsN/QisBu4mVSuMufOtFecYYc2hMvR62 6DjrL8t5Jrx+Y/vK0MV9YUrB/g7Nq98Zz9RaF+lfBYDU7n+OelCtZ0BxVVubuwCPA1fR eQVF7ZIQkp2FfHcikzHB1ODlPtCEzOvbbfJHiLbprqQfyoSK2ewwstXlKP8hOFQNzaUD omyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="gglIK/h4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn6-20020a170906c0c600b007c4f9ce306esi8012885ejb.729.2022.12.19.11.39.13; Mon, 19 Dec 2022 11:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="gglIK/h4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232361AbiLSTdh (ORCPT + 70 others); Mon, 19 Dec 2022 14:33:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230091AbiLSTdd (ORCPT ); Mon, 19 Dec 2022 14:33:33 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3250F12ABE for ; Mon, 19 Dec 2022 11:33:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id a5-20020a25af05000000b006e450a5e507so11930239ybh.22 for ; Mon, 19 Dec 2022 11:33:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1BXl9vy0f2f/11VKxHLckXglqOMtK0anh34YjL4SpoA=; b=gglIK/h4ez0+aqt1O+U+ScB+Bh/FoHfv+OJW2X6p/mpdxgf9sq0WpIXhUJ5u7bEa4H 10mjJki54ttBlnuEVGRrt4nfvk3DPFYhdmDXX9JB4EHkXVknVwm2r+YbixMYY8N6UZas 5vXteQ+W/jinCVg1i3jH3Sq6GdLGbtJiJEgL0VHwTnjBd1sEoZok1EKLr4pFYMROU+p0 YYRYQlwDq4TmyqJr6mbWUEz8O0t2eI0OU1/lIEPwriuBAiJG2+lZYudkRgiaKxtj40mh nzufqCnqhxprw5h6I+7GHHOA9d0zJQesZdwXXEQXREzaIOdk4g+/4kVnus4E4cmOz0rr e0cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1BXl9vy0f2f/11VKxHLckXglqOMtK0anh34YjL4SpoA=; b=nykCQRm0Xa9MXBQI+/4DwfmrCbMl3cy3YMb61gbNWkdZR/XGzPvj6p3nwwRRCGYqGm 8wd08CchTtKB6bbxhF/vTi3Db7B8VaoGh5GhQBJ93ecNq52IdR58TvOQTDmg9Xqck70i CKwpdvv5JTocRtj36YScTasJaluVZ7pCxMtQwesDxt6L0A+2WNm0jlILwPaCfsFi6HEw 8doVAqxwz+mUwbBevPrT9O+RgcYMgKRRY/T/Av4SLMvyQpJKNDim67OjhFTeFvJBnEIv ++NtAzHCcPt7snB1MT+doma2xCnwvIgxsam9o6w+eM40/TuJkkZv/v5crGeomITj9kpS 4btg== X-Gm-Message-State: ANoB5pkbmIll0EzJ3cZ5KzYSXOCL1FFBE6jEraPpJku7PgX3pKU9nDSX /P47HWmDM7LVWOKdes07rtvmt1E= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a25:b885:0:b0:701:49ca:8ae8 with SMTP id w5-20020a25b885000000b0070149ca8ae8mr21490186ybj.553.1671478411506; Mon, 19 Dec 2022 11:33:31 -0800 (PST) Date: Mon, 19 Dec 2022 11:33:29 -0800 In-Reply-To: Mime-Version: 1.0 References: <000000000000a20a2e05f029c577@google.com> Message-ID: Subject: Re: [syzbot] KASAN: use-after-free Read in put_pmu_ctx From: sdf@google.com To: Peter Zijlstra Cc: syzbot , acme@kernel.org, alexander.shishkin@linux.intel.com, bpf@vger.kernel.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, mingo@redhat.com, namhyung@kernel.org, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/19, Peter Zijlstra wrote: > On Mon, Dec 19, 2022 at 12:04:43AM -0800, syzbot wrote: > > Hello, > > > > syzbot found the following issue on: > > > > HEAD commit: 13e3c7793e2f Merge tag 'for-netdev' of > https://git.kernel... > > git tree: bpf > > console+strace: https://syzkaller.appspot.com/x/log.txt?x=177df7e0480000 > > kernel config: > https://syzkaller.appspot.com/x/.config?x=b0e91ad4b5f69c47 > > dashboard link: > https://syzkaller.appspot.com/bug?extid=b8e8c01c8ade4fe6e48f > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU > Binutils for Debian) 2.35.2 > > syz repro: > https://syzkaller.appspot.com/x/repro.syz?x=15e87100480000 > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16ceeb13880000 > > > > Downloadable assets: > > disk image: > https://storage.googleapis.com/syzbot-assets/373a99daa295/disk-13e3c779.raw.xz > > vmlinux: > https://storage.googleapis.com/syzbot-assets/7fa71ed0fe17/vmlinux-13e3c779.xz > > kernel image: > https://storage.googleapis.com/syzbot-assets/2842ad5c698b/bzImage-13e3c779.xz > > > > IMPORTANT: if you fix the issue, please add the following tag to the > commit: > > Reported-by: syzbot+b8e8c01c8ade4fe6e48f@syzkaller.appspotmail.com > > > > ================================================================== > > BUG: KASAN: use-after-free in __lock_acquire+0x3ee7/0x56d0 > kernel/locking/lockdep.c:4925 > > Read of size 8 at addr ffff8880237d6018 by task syz-executor287/8300 > > > > CPU: 0 PID: 8300 Comm: syz-executor287 Not tainted > 6.1.0-syzkaller-09661-g13e3c7793e2f #0 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS > Google 10/26/2022 > > Call Trace: > > > > __dump_stack lib/dump_stack.c:88 [inline] > > dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106 > > print_address_description mm/kasan/report.c:284 [inline] > > print_report+0x15e/0x45d mm/kasan/report.c:395 > > kasan_report+0xbf/0x1f0 mm/kasan/report.c:495 > > __lock_acquire+0x3ee7/0x56d0 kernel/locking/lockdep.c:4925 > > lock_acquire kernel/locking/lockdep.c:5668 [inline] > > lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633 > > __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline] > > _raw_spin_lock_irqsave+0x3d/0x60 kernel/locking/spinlock.c:162 > > put_pmu_ctx kernel/events/core.c:4913 [inline] > > put_pmu_ctx+0xad/0x390 kernel/events/core.c:4893 > > _free_event+0x3c5/0x13d0 kernel/events/core.c:5196 > > free_event+0x58/0xc0 kernel/events/core.c:5224 > > __do_sys_perf_event_open+0x66d/0x2980 kernel/events/core.c:12701 > > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80 > > entry_SYSCALL_64_after_hwframe+0x63/0xcd > Does this help? Let's maybe try it this way: #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git 13e3c7793e2f diff --git a/kernel/events/core.c b/kernel/events/core.c index e47914ac8732..bbff551783e1 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -12689,7 +12689,8 @@ SYSCALL_DEFINE5(perf_event_open, return event_fd; err_context: - /* event->pmu_ctx freed by free_event() */ + put_pmu_ctx(event->pmu_ctx); + event->pmu_ctx = NULL; /* _free_event() */ err_locked: mutex_unlock(&ctx->mutex); perf_unpin_context(ctx);