Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp175249imd; Wed, 31 Oct 2018 16:50:14 -0700 (PDT) X-Google-Smtp-Source: AJdET5eGZcdSLy7AKgeF/sF1Fcs5AbJ/J2FTz09PYwnJTTKqVAScY4fRoq5Til07EMCefRBaFxU+ X-Received: by 2002:a62:42dc:: with SMTP id h89-v6mr5593097pfd.0.1541029814812; Wed, 31 Oct 2018 16:50:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029814; cv=none; d=google.com; s=arc-20160816; b=pKXwq6e4Y+kNeCyQ5baSlqyHz9662abyz5//EpyrBrK3ikLqs4rl4xCXgxwKDgd2i5 nlL+cyhX2JFBz95tTOmrbjL1C0mT6rQMkRkm+rKlhWzJ8lI2RQdWZ594QjiHuTIZlYo7 wKJEynEkiLNp7ktXvXp6nVmwaQPwRX6ILVAeJjCgNGN4LO11prFVK6qFRVcx8WRsmpHX 2mVpM8kbSYncvcaREvTB1FDTK1QjAHl7UwJvVwaddRTNKndMxroxpL1AO/REadECqCr/ 0PT4/PiNwXXhEwkS5tlHjLW2YoIy6E3DV+5xpRoj1DVI6WUMWi7Z0cTTRSd7vY0OW+jO 4qVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=WkA2SHMM1murwRKr6vxWODijdDP6fGmrYO7kh9WkbrQ=; b=W+oevghEzf5CNB/xeGcVM3CDeTdddMZ/aLficf4Iz4rvUfYCRY/sneFmeJm3xd5Ti3 Vcn9mtGZ3mij8DZWPDncumQc3T/uzfPIRcaXyI15/YOfSxqCP4ZIS5E7e6gFUQYhJfX0 XC1u8wf5xeubIq4tQxQ7E/3YFXXsT+4XKiGgsOSzOWIw1ZbBHdSYPO4fS6YKP5IcEfeG ePauPn2jQnhVCQbB9U9uB7jyvIflLOUJyPVd4eJZQmDq7EIVTpOI+VDSW3Jojjm4F1Md 77akNy/955SJLkyRZ1EkonofE4KUNdwzuGdR6iKbp0sfv9phh3bnpq7EaB0gpdlAbipp CKgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VWW+Li1E; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o9-v6si29731512pfe.283.2018.10.31.16.50.00; Wed, 31 Oct 2018 16:50:14 -0700 (PDT) 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=VWW+Li1E; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728357AbeKAIGs (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:53964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbeKAIGr (ORCPT ); Thu, 1 Nov 2018 04:06:47 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F382120838; Wed, 31 Oct 2018 23:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027197; bh=5EqJv7ncqkFpEAiGQyfgKvF+NY2jtRsfMi5tulWvSic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWW+Li1E5rJZY84PtZvjVQsd1J2iLV/syt4WSuoT9887/s0NfnBcCGO16Oke8qSBE oqAkQxoMqOgVJ7PPy6zdoZogkIZz5UP2t0URAqV056pxjS8oWeddiTL+EqRnalBqka XEbLgQw8qIlI/MDfFPEMtqFRRXr8q4J1VUGZG7ko= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Anil S Keshavamurthy , "David S . Miller" , Linus Torvalds , "Naveen N . Rao" , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL 4.19 060/146] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() Date: Wed, 31 Oct 2018 19:04:15 -0400 Message-Id: <20181031230541.28822-60-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/kprobes.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index ab257be4d924..4344381664cc 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -700,9 +700,10 @@ static void unoptimize_kprobe(struct kprobe *p, bool force) } /* 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 kprobe *ap) /* 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 kprobe *p, bool reopt) #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 kprobe *orig_p, struct kprobe *p) 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)) { /* -- 2.17.1