Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2662604pxj; Mon, 14 Jun 2021 04:20:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwirLFzOLJIn7/uTcHEjbGBGT7+rABekziIT/lkOQXWxVdLebkHSelwUmci4tjDNT6+ceR6 X-Received: by 2002:aa7:c758:: with SMTP id c24mr16999536eds.188.1623669616120; Mon, 14 Jun 2021 04:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669616; cv=none; d=google.com; s=arc-20160816; b=GnrUk8HTC089w/Rte4ei4SLOpPSERJy9l3n9PnvcVuX1JP4vTFqHTxMAZ8uNmPdw9U cd8r5jU2w72Ber8twcv9Yy9gm0W68h9aAqalId4zxh2voRwrxIHW37xmaPg2MTIWUOWI md3/PGdyrFd7r6qewzCjwztJd1M6LAoVfkUghfkG7FSKFVv8at33kZ3Yf6LDZRKexTvJ ZgFi5ORlF1Fhnv7idDm6jxAgo6GdRkHedQ8MMiobJ9B5+K2ZLbvYhOriMnTq1xVzO7sG +KlBA/WkqYkHcsu56VrW890fyzwo/1WGC2p0EcgF4qZWWlbcUqqdYx0oRH0lTLqlOqMG rQWA== 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=xdc3/uWNmN+PmyXBt7gxE2hojKelRIuP5bfXQhfNl9U=; b=I7WrCqWwcqpr4pG9a9qmZV159eirD7raZcaVY8m8mf6N7OkepPKhhpUz0KxeTSD193 ZNdDrkt3BqIcxgcRsuzcsrfXeM0V/FBLyGvN+T1fHR9tF+DXaymC5T3v6Dv2acLqJDtg HbmV2crLAihf3PYl99/JqYH1ClD1J62YfYISxtMT3uH4Wg4PW2RFia+1abLlJjpckUCF eqnILoGbEjwZ3obwt6kxJ+qDyzhLXtnWjPrcyZpbhmUU/pum3sUkY4HkmxZs4V17r8ig BTLkli80sJsfUx+WO5lm3FHhnbWR7xhHOpNV90LKAnxYWRRx8QAl4iKWmNrytzfRWaq3 diWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WLtNvaOR; 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 x5si12076293edq.391.2021.06.14.04.19.54; Mon, 14 Jun 2021 04:20:16 -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=WLtNvaOR; 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 S236031AbhFNLUF (ORCPT + 99 others); Mon, 14 Jun 2021 07:20:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:39676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234341AbhFNLHu (ORCPT ); Mon, 14 Jun 2021 07:07:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B92F161931; Mon, 14 Jun 2021 10:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667566; bh=MRpctEw6FPJxcbjka1V1PqzgPH93sBQyofjXrHn/N78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLtNvaORvDjzCp+8t2+XhWliQ6kDEPypphFc44NvT71WQDW2SAgUr04txLhvmo68v ibi2CNeHspNhk5mM2r1T2eW+m1O9W6JOgAogpuJ1okBX4zWhkyPdPVEmYC9PzypzNM BF492mCgeu1Wv7991k2bSkmeeLuQfz8f9z8Agjeg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+142c9018f5962db69c7e@syzkaller.appspotmail.com, Marco Elver , "Peter Zijlstra (Intel)" Subject: [PATCH 5.10 113/131] perf: Fix data race between pin_count increment/decrement Date: Mon, 14 Jun 2021 12:27:54 +0200 Message-Id: <20210614102656.852209876@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@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 From: Marco Elver commit 6c605f8371159432ec61cbb1488dcf7ad24ad19a upstream. KCSAN reports a data race between increment and decrement of pin_count: write to 0xffff888237c2d4e0 of 4 bytes by task 15740 on cpu 1: find_get_context kernel/events/core.c:4617 __do_sys_perf_event_open kernel/events/core.c:12097 [inline] __se_sys_perf_event_open kernel/events/core.c:11933 ... read to 0xffff888237c2d4e0 of 4 bytes by task 15743 on cpu 0: perf_unpin_context kernel/events/core.c:1525 [inline] __do_sys_perf_event_open kernel/events/core.c:12328 [inline] __se_sys_perf_event_open kernel/events/core.c:11933 ... Because neither read-modify-write here is atomic, this can lead to one of the operations being lost, resulting in an inconsistent pin_count. Fix it by adding the missing locking in the CPU-event case. Fixes: fe4b04fa31a6 ("perf: Cure task_oncpu_function_call() races") Reported-by: syzbot+142c9018f5962db69c7e@syzkaller.appspotmail.com Signed-off-by: Marco Elver Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210527104711.2671610-1-elver@google.com Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4547,7 +4547,9 @@ find_get_context(struct pmu *pmu, struct cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu); ctx = &cpuctx->ctx; get_ctx(ctx); + raw_spin_lock_irqsave(&ctx->lock, flags); ++ctx->pin_count; + raw_spin_unlock_irqrestore(&ctx->lock, flags); return ctx; }