Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3483111imu; Sun, 11 Nov 2018 16:07:34 -0800 (PST) X-Google-Smtp-Source: AJdET5edDayKMRp1AIrO/Q5kLB6cAknGJhGjCcQqSN5sWoAPlNKsMDXNA6QSBfF+tdEFACMNqxCp X-Received: by 2002:a63:ff16:: with SMTP id k22mr15576262pgi.244.1541981254885; Sun, 11 Nov 2018 16:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981254; cv=none; d=google.com; s=arc-20160816; b=Tee+5kS/Yt3Ksmw74vJmNeVrmJx+zF9laauPxTP0JKJ2YzNdUSNwY9O3esvzXA6IFL Xi0FMAOpZ/qunNtex2BtAm4nNbXYlnI6m5Ut89foLg6mhmkI2QAiT4MJfkMJVUu3d9Sf xmmWbJwaa28f4Q701o4K97N69DC6EYwc/S8JTBy8RPVx2wwibHFTjplkBVP1G0AHcnW3 NDscvdgmULygN4MhlLugKAJtXLwSU1iVSkHQpPFSSgRb50Srhis+aoO5PrwlXRv1aPdc 6Mt/PpOImL55FbOUHpKGUiSsQflUCxcgDgDm7Rp8GZJmS8F4kw1ftxLXt7dROPJHG/5c YlaA== 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=guSjpHZnQWNmL325mbfppUjtpSyZWlLbiNfZ0Pfdc2Y=; b=j9+vUqZm95D9eligxpGNDSRwWy+y5q2xDTsWrv/JEQkW1qU1Un912jK+V6f2XP1z7r nEIBP/ITrz7MOf5OpMz9ie0azbk3/Tyc3GFlrGHyIPHXZLaWKBTY3F9HK1Z46fsr07TK 1w/XjRWAqqm4zslxu7NW2muHiCVkL3o+JRTV3OUOYQpC5ZxEPv7GdGYGkbAFVoMAamsM YCKEEan/8P8ns/Ia8tgrGUXNWMAtXuXDxT/QP3qPbhVWF5JfOC368srEgbsAVHO0aBF0 WnDRGL47O+GLrvsGuPT86Qy0qU/Y438+KVTZLO+uSOcXlE/zLlxKibsfE6U2gVYiXfNU pyfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qB208vmT; 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 2-v6si17760395pla.223.2018.11.11.16.07.19; Sun, 11 Nov 2018 16:07:34 -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=qB208vmT; 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 S1731793AbeKLIRh (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:33680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731593AbeKLIRf (ORCPT ); Mon, 12 Nov 2018 03:17:35 -0500 Received: from localhost (unknown [206.108.79.134]) (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 2C91321527; Sun, 11 Nov 2018 22:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975259; bh=bOV1Hj+Gar7wWxP5b+4ePYEqFWkMlJf2ecw/p1mY/wI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qB208vmTSR7BGhpk3H1mrEdJr3ou+KwaFe6s1tf6+ko4N+pUO0NT1L0sUfhBJMsCL 9CxWuPsp9xbXnP0e1b9+mgP6dnWr1oiYPwZErWAA+VLhMnkl9tPthXeTIHOvfE7oua JxdWO474Y65GLe4675DevxYofxKPPRyLQewm35Iw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Anil S Keshavamurthy , "David S . Miller" , Linus Torvalds , "Naveen N . Rao" , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 105/361] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() Date: Sun, 11 Nov 2018 14:17:32 -0800 Message-Id: <20181111221634.324038806@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu [ Upstream commit 819319fc93461c07b9cdb3064f154bd8cfd48172 ] Make reuse_unused_kprobe() to return error code if it fails to reuse unused kprobe for optprobe instead of calling BUG_ON(). Signed-off-by: Masami Hiramatsu Cc: Anil S Keshavamurthy Cc: David S . Miller Cc: Linus Torvalds Cc: Naveen N . Rao Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/153666124040.21306.14150398706331307654.stgit@devbox Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/kprobes.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -700,9 +700,10 @@ static void unoptimize_kprobe(struct kpr } /* Cancel unoptimizing for reusing */ -static void reuse_unused_kprobe(struct kprobe *ap) +static int reuse_unused_kprobe(struct kprobe *ap) { struct optimized_kprobe *op; + int ret; BUG_ON(!kprobe_unused(ap)); /* @@ -714,8 +715,12 @@ static void reuse_unused_kprobe(struct k /* Enable the probe again */ ap->flags &= ~KPROBE_FLAG_DISABLED; /* Optimize it again (remove from op->list) */ - BUG_ON(!kprobe_optready(ap)); + ret = kprobe_optready(ap); + if (ret) + return ret; + optimize_kprobe(ap); + return 0; } /* Remove optimized instructions */ @@ -940,11 +945,16 @@ static void __disarm_kprobe(struct kprob #define kprobe_disarmed(p) kprobe_disabled(p) #define wait_for_kprobe_optimizer() do {} while (0) -/* There should be no unused kprobes can be reused without optimization */ -static void reuse_unused_kprobe(struct kprobe *ap) +static int reuse_unused_kprobe(struct kprobe *ap) { + /* + * If the optimized kprobe is NOT supported, the aggr kprobe is + * released at the same time that the last aggregated kprobe is + * unregistered. + * Thus there should be no chance to reuse unused kprobe. + */ printk(KERN_ERR "Error: There should be no unused kprobe here.\n"); - BUG_ON(kprobe_unused(ap)); + return -EINVAL; } static void free_aggr_kprobe(struct kprobe *p) @@ -1318,9 +1328,12 @@ static int register_aggr_kprobe(struct k goto out; } init_aggr_kprobe(ap, orig_p); - } else if (kprobe_unused(ap)) + } else if (kprobe_unused(ap)) { /* This probe is going to die. Rescue it */ - reuse_unused_kprobe(ap); + ret = reuse_unused_kprobe(ap); + if (ret) + goto out; + } if (kprobe_gone(ap)) { /*