Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4876689pjb; Mon, 27 Jul 2020 07:23:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI3vPM3xqjXm+Gs4NpDiKoHTamOVtku95J0V0iIrWhLKjNITwiAaZOB+un9+q95WOAeu6t X-Received: by 2002:a17:906:3789:: with SMTP id n9mr22440239ejc.512.1595859821100; Mon, 27 Jul 2020 07:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859821; cv=none; d=google.com; s=arc-20160816; b=bGOlegX1WLeI2Po03m1XQo8YzxQGxANuwFEIjqMuY0i8CMrTxdQl66+7kjfVwJ+vep MiWQUwJ/eFlNcTE+5HmydYO6i/Q/19EkqqEcKuQX3LXwyVDx8BCVIQITpkc6ynDowzEW ymLMIcZ0R/AcxQm6hKu9w3OonZ/unfLUlRvQQoS0qCaGdwURogobNZuGJxHgsdGWe4yg CcfgIHaIAYtkHXlT5qOWcocH3HvcbpyhDBwj8emKG1azdasiiYT4uS+GMMQeIJWYODI3 yM+nEocxeniPNWa0hvU93dpivu0++rmMMDnQckDPG3NAjM3zTGJZA9dzs7wVLOJDVjnQ QRIw== 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=qLsXWrPjnBUjIs7pzaFpK1T2jGxabp5W5/QTF0gsL4w=; b=0ow2xBNo/+F2qMHbhLUXL+tCmevYV2mHfnvvdH/Lq48oye0/1pf3isbd+ZgEzQgj0H ACfVSzBPxG1MTeU124Vf3w4dzDM58iA5SZ1ET5vFntIVzvE/JNKFUUqgyLauCADzWwPU zXjqaBfreisROssUZnUjXZjFUMksGi7nQJ2w9rYaPJeIEGgksd3mBABfjLkVzupT/uIl u2at1mUVIW+Hpt5zAkRoRMWRqO5uvpTtkZ98ALo8YDAKIkb8v9uDaUUcxqeOrIH+yOdF nWI/sLEL9+yqBCMU38icCGOzCSjgdOr0i8uYrjvp0nPlYXFDU9NLc/DDYBEfGeRcY3uD UXHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rNDYWln5; 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 w23si5992488edx.588.2020.07.27.07.23.18; Mon, 27 Jul 2020 07:23:41 -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=@kernel.org header.s=default header.b=rNDYWln5; 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 S1731479AbgG0OUA (ORCPT + 99 others); Mon, 27 Jul 2020 10:20:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:48000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731464AbgG0OTz (ORCPT ); Mon, 27 Jul 2020 10:19:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 4C29F2070B; Mon, 27 Jul 2020 14:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859594; bh=r9nzgQaeZR71FIFN/VCqxekjVrWwR2TUFPDQJB65kYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNDYWln5ty1kY6cPo73Jc0U/ztk68DR32TGBkULi3stvNoJHuU8+D2LSK6eqs8q9h GfzX/2d76Q0owrzNcp1W++QPaNes31PbkV4gkmyQlpS4UkRX6CXVKIKlbbkcWZtIMU agS8p/1Qjm7wG+QkB5zXcy3Cwt9lkI1w0WKPZ/tQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Merey , Oleg Nesterov , Ingo Molnar , Srikar Dronamraju Subject: [PATCH 5.7 032/179] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression Date: Mon, 27 Jul 2020 16:03:27 +0200 Message-Id: <20200727134934.230441866@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Oleg Nesterov commit fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a upstream. If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp() does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used to work when this code was written, but then GDB started to validate si_code and now it simply can't use breakpoints if the tracee has an active uprobe: # cat test.c void unused_func(void) { } int main(void) { return 0; } # gcc -g test.c -o test # perf probe -x ./test -a unused_func # perf record -e probe_test:unused_func gdb ./test -ex run GNU gdb (GDB) 10.0.50.20200714-git ... Program received signal SIGTRAP, Trace/breakpoint trap. 0x00007ffff7ddf909 in dl_main () from /lib64/ld-linux-x86-64.so.2 (gdb) The tracee hits the internal breakpoint inserted by GDB to monitor shared library events but GDB misinterprets this SIGTRAP and reports a signal. Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user() and fixes the problem. This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP), but this doesn't confuse GDB and needs another x86-specific patch. Reported-by: Aaron Merey Signed-off-by: Oleg Nesterov Signed-off-by: Ingo Molnar Reviewed-by: Srikar Dronamraju Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200723154420.GA32043@redhat.com Signed-off-by: Greg Kroah-Hartman --- kernel/events/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -2205,7 +2205,7 @@ static void handle_swbp(struct pt_regs * if (!uprobe) { if (is_swbp > 0) { /* No matching uprobe; signal SIGTRAP. */ - send_sig(SIGTRAP, current, 0); + force_sig(SIGTRAP); } else { /* * Either we raced with uprobe_unregister() or we can't