Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1746926ybg; Thu, 30 Jul 2020 01:19:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7WsnZbz4PvFv3OtDIpMvHIFbaaGAmvPfyBG0TP3rqS+sb1VmwDkachVdSWA9Ro232GH3E X-Received: by 2002:a17:906:cb91:: with SMTP id mf17mr1469317ejb.527.1596097157981; Thu, 30 Jul 2020 01:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596097157; cv=none; d=google.com; s=arc-20160816; b=eJez4kaKSn7tvp66OdDWhsibrPIgMaQ20TGzDqxY8VEFxDE+2sYXvKLIBnPDZ2cs1H yEJHtr8QkT/oRvLwn0V0G0QUR3L98L/JIGUNuaKsX3U/GcbYCk9qeLOgwf6G5D9VxjZ9 Eb4qM29wfsiFUk0o6qaOwcLCwKRMrGH6setyXfx86fcXH4uV4EbRi0TFGRONx98vY00l 5rJBVn6SjmYVmX+FzjwKqVZYlPVOZa3lgwL0LczkRgzvKJPtmtZYqO8V2VK7B6xrGugp vs3mmA6Xq3yPIEqxzeeslbZ+I0crvv8onIzE6c95pQ/llaAbban8vv0V6/PeRSQ8rIg3 RUTA== 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=l6QnTpzcGJBJ5NUMPoIITqjUirYq9bGkkkXt2TE006A=; b=r2CBZS8DfTdWeUxq+EpHw6Nenj+jtCHMp79+LuMyY/rX1AeaSKjjsHJYS5H5Ft80P0 4VNb53ch1TWArZM6ol46qFTvP4xoWK++Xb8SjAUFvX2ji4tWjLJur3peXNXXRO7AfO8l 28G8n/kFQRabxXdc9tV2F4lgBVHmQVcPbDwodIV1xpuKn80iHbwjvl5uuzZX2MF8p6w+ S5GXDxcFBnaRmmV1uMqZHyMIPelYM4HafIc0AQHUbfkTc6HEs+ZMTjqiLih8RY/lhBsp 4La9Yu82bEUv116KKoZQqPtL9DmZrEphdrmeaEEl1uGPA9lrk7h8gNuNTjEdr08n5Jb5 buVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K1EQXe1+; 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: <linux-kernel-owner@vger.kernel.org> Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si2917266ejy.245.2020.07.30.01.18.55; Thu, 30 Jul 2020 01:19:17 -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=K1EQXe1+; 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 S1730017AbgG3IQ2 (ORCPT <rfc822;vinadhy@gmail.com> + 99 others); Thu, 30 Jul 2020 04:16:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:50072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729263AbgG3IK6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Jul 2020 04:10:58 -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 BA9C120838; Thu, 30 Jul 2020 08:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596096658; bh=fK3nluCrsd7GJqBhfiZGDJK2iUkNilXgPplE97Uy3us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K1EQXe1+NuHym3RsNhK1pQuj6NMTuh5tKg4GbIXMTh6ieMFUjMrK4dNkYVhtv2rk/ KTklDnjcgu3wd11U9HlR9MwbAfgEOAq6YoiIGUM+sfi26jzahq0dfW6WnWT3tO20hk u5OTKKFMFXvlFDcrnyBqZuk0fuzmyGmwStB9GspY= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org, Aaron Merey <amerey@redhat.com>, Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@kernel.org>, Srikar Dronamraju <srikar@linux.vnet.ibm.com> Subject: [PATCH 4.4 11/54] uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression Date: Thu, 30 Jul 2020 10:04:50 +0200 Message-Id: <20200730074421.757727943@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200730074421.203879987@linuxfoundation.org> References: <20200730074421.203879987@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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org From: Oleg Nesterov <oleg@redhat.com> 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 <amerey@redhat.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200723154420.GA32043@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- kernel/events/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1875,7 +1875,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, current); } else { /* * Either we raced with uprobe_unregister() or we can't