Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp845436imu; Tue, 11 Dec 2018 08:25:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/WrIGf3YwgAeIyK0/lHvrdL6cDwuSPQeQXl3bdnKalJx1wxayI28/ceZIQl5pw66Y80kR3N X-Received: by 2002:a65:4049:: with SMTP id h9mr14926420pgp.304.1544545548819; Tue, 11 Dec 2018 08:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545548; cv=none; d=google.com; s=arc-20160816; b=NsJKCUY2ZQftETYIGUdfc4D2NgKhkC1VwAB9Oy4+NoOn3JobH9Kbklnt6u0fe3EkTM W9wyUbXQSTjSLDUEagKS2PTPrH6fURfepKgux0Pcqk9dUHsoMks08TuasFw81zfSoaqR isWhghEWU7swd64TihkOESyC7hLZrskw9yVso5YfGMscFRHUot+KNiR18A79dvaymlsU ahcq698/P5lDrvJGPTnc44woXYW9/67oVCfYHHQ2YG5gMODx6L6GtBkhjTIkxEkYEgxb 19vlMvLek1xnKP7FPxdQG+9K4oLAj0F6rg8PTf8fNRIcVKqaUkdccl5ztVtb9GU/fsKm ZY7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8e+k/Sn07z3tyiq3hHwoT1Kl2snSMgOXxdLQS2C/dEk=; b=NzKaZgNM5yjq9+WD/8sR5RgQvd96bAffJ5cbJxSKoEWuII6+pe31Q3efid99v0X/pL 4iN10AqAzQfkGiUV4NSfS4bffGe4/QeHCzJDNqx19aheVyWwzuQOGcIdE9T8+M5efEd5 bdlLZOlXx3VL06HSSGu0rf6WDhQXvebK3Q0ODwPbSRopo0WZ9dEIIvdxvIraGpiP1ZPa 76Zpjwojy29D1WXQ3ARvUJyc5ITqwCCmyl5wDQAPy/5CJVPrEfGU9Nkg/wa4xHM82cy5 CteL5W7bsdW/KaxjjyLcBZa6EXtZIPoHG5BM2+V78R4+u8DIbIRmH0Q+W786PXnoeQvW M0ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vzq0YnCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si11962766pgq.82.2018.12.11.08.25.33; Tue, 11 Dec 2018 08:25:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vzq0YnCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbeLKPnH (ORCPT + 99 others); Tue, 11 Dec 2018 10:43:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:59490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727201AbeLKPnF (ORCPT ); Tue, 11 Dec 2018 10:43:05 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BD6020672; Tue, 11 Dec 2018 15:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544542984; bh=L0pyjnCgMRxwnKDdPw+8kYHH0y5EdC8MRkDD243SgAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vzq0YnCi5qLS6rx3mJZRMGvLPBiCKTzKB9zdpCD7NIEpcqfaD0ttwYeZlWWb28u3r HVHENkABoq2wu7ewmehhszsjj4XLvjI3WtmVy32HI28cUN45Er4zgKUBakC22A30B4 jEgcuEtSoMi2nGoj0mPKsKtJ/peDdl7/w+mayCvM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrea Parri , Oleg Nesterov , Alexander Shishkin , Andrew Morton , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Namhyung Kim , "Paul E. McKenney" , Peter Zijlstra , Stephane Eranian , Thomas Gleixner , Vince Weaver , stable@kernel.org, Ingo Molnar Subject: [PATCH 3.18 23/54] uprobes: Fix handle_swbp() vs. unregister() + register() race once more Date: Tue, 11 Dec 2018 16:41:11 +0100 Message-Id: <20181211151547.268639037@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Parri commit 09d3f015d1e1b4fee7e9bbdcf54201d239393391 upstream. Commit: 142b18ddc8143 ("uprobes: Fix handle_swbp() vs unregister() + register() race") added the UPROBE_COPY_INSN flag, and corresponding smp_wmb() and smp_rmb() memory barriers, to ensure that handle_swbp() uses fully-initialized uprobes only. However, the smp_rmb() is mis-placed: this barrier should be placed after handle_swbp() has tested for the flag, thus guaranteeing that (program-order) subsequent loads from the uprobe can see the initial stores performed by prepare_uprobe(). Move the smp_rmb() accordingly. Also amend the comments associated to the two memory barriers to indicate their actual locations. Signed-off-by: Andrea Parri Acked-by: Oleg Nesterov Cc: Alexander Shishkin Cc: Andrew Morton Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Namhyung Kim Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: stable@kernel.org Fixes: 142b18ddc8143 ("uprobes: Fix handle_swbp() vs unregister() + register() race") Link: http://lkml.kernel.org/r/20181122161031.15179-1-andrea.parri@amarulasolutions.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/events/uprobes.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -612,7 +612,7 @@ static int prepare_uprobe(struct uprobe BUG_ON((uprobe->offset & ~PAGE_MASK) + UPROBE_SWBP_INSN_SIZE > PAGE_SIZE); - smp_wmb(); /* pairs with rmb() in find_active_uprobe() */ + smp_wmb(); /* pairs with the smp_rmb() in handle_swbp() */ set_bit(UPROBE_COPY_INSN, &uprobe->flags); out: @@ -1860,10 +1860,18 @@ static void handle_swbp(struct pt_regs * * After we hit the bp, _unregister + _register can install the * new and not-yet-analyzed uprobe at the same address, restart. */ - smp_rmb(); /* pairs with wmb() in install_breakpoint() */ if (unlikely(!test_bit(UPROBE_COPY_INSN, &uprobe->flags))) goto out; + /* + * Pairs with the smp_wmb() in prepare_uprobe(). + * + * Guarantees that if we see the UPROBE_COPY_INSN bit set, then + * we must also see the stores to &uprobe->arch performed by the + * prepare_uprobe() call. + */ + smp_rmb(); + /* Tracing handlers use ->utask to communicate with fetch methods */ if (!get_utask()) goto out;