Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp737030pxb; Tue, 14 Sep 2021 07:42:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQCYaVvbT39A5vka5OksiCz+/gZAbLUeaOnXCf7zUVpcwqZzJjhaPiZr/OBPIwDwvfTCqK X-Received: by 2002:aa7:d598:: with SMTP id r24mr19593424edq.285.1631630559598; Tue, 14 Sep 2021 07:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631630559; cv=none; d=google.com; s=arc-20160816; b=dC5GwO1ndDQSk8MCRaskiJ+bTUp8dFD5c6h6LvSrLx29BG8agPn6ctwcV4ysPrlZPC Bi620UbG6j3uywb9pHVSWTJDEuAMAeLHIKVZJnLYTxhtAUu8aD0Ogbp89CmXIqJo37EL 5PPwnj5npkvsYG9ngU31G3TJX56EfSaCUjhuqonsqPLcU51hPK0azQPUXanmPsUj6Yn2 IlPfZN9XBipGjNXJWmLIbzmAjT/jIg4m3iaiIrp9P2NRrdNcZtw5oS/O2SASaHTS4K80 fIf0d5X3lbk9ADRHG+6WQPMuYXvlXtj9WiJ0Yw4tyr/98tZjKbkqLpZO7nkxQq5TcQG0 4KKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8Up3/9po/ltr4TF0/CGkwnoYfeiiesLHHw14G6mgUkw=; b=hXFJhrgRcsZery2fDOCZkZtbdT1oGtGwsZ8so5r00U3h1PkmGnWhac85isW97cgRn7 kxr/WHXCA029Lt3/TiLU/jVP9BnJh/+vIRTi7uOYbW8psaxQdoWjiuzaVeZ207sFlF3f l66m+U+MuN7Lq5CB5S8BQSWQM4cpIqMkoW7jUH3bMxOIrzJcctjCunDCNNvjYJIA1QTo awDZAQS4GzCiMUldrlP9g9zEpHUWHJFKxtOxIIHTnYn8tB/wEwzyM3PD1P8pnQz6AR2I gqnOPBsScsMPtpg5oZnxouKQX1YD3VgxKBIzQRP2lZp77nh7dNDPV5MNFSIC7FYnhTOh DCZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N5F7dsm3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gq9si10077561ejb.654.2021.09.14.07.42.12; Tue, 14 Sep 2021 07:42:39 -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=k20201202 header.b=N5F7dsm3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233694AbhINOj7 (ORCPT + 99 others); Tue, 14 Sep 2021 10:39:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:60920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbhINOj6 (ORCPT ); Tue, 14 Sep 2021 10:39:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6CAC1610CE; Tue, 14 Sep 2021 14:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631630321; bh=4xQiQDDV7nXJL8Xan+15i4FwcNOTqTiYzYCdCLjItZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5F7dsm3oC3uWyspwozTKIHTqoDUSpeWzd2cFIzjDhYfwuHRmblgxYcBS5r4Q0hms fV6v7crr6GMxQwrgBCCrY8zspDHYWnYlynmfEFDiFfSdHSuYNpSfYCIPmyUL6uVj6C v6g9TBqpQQk24LXe4gWje5oEYx9+og5T5QUDYso7jq/CcYRb1pWEWy6YMhY1nlj83x pbsBqG8FU5CXWkJjtxzRvRL5FT2Eem287aIg7Tz9NYhMLpoWEd8NjMBExtzw0PW4tf 9jbYizbkmoOzNSXoB+A1KHa+ItddVhB5fNLXLaNScI8Vjydfb90NMdcNPaLrRPNzxF O6FpkVf8diEJQ== From: Masami Hiramatsu To: Steven Rostedt , Josh Poimboeuf , Ingo Molnar Cc: X86 ML , Masami Hiramatsu , Daniel Xu , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kuba@kernel.org, mingo@redhat.com, ast@kernel.org, Thomas Gleixner , Borislav Petkov , Peter Zijlstra , kernel-team@fb.com, yhs@fb.com, linux-ia64@vger.kernel.org, Abhishek Sagar , Andrii Nakryiko , Paul McKenney Subject: [PATCH -tip v11 01/27] kprobes: Do not use local variable when creating debugfs file Date: Tue, 14 Sep 2021 23:38:37 +0900 Message-Id: <163163031686.489837.4476867635937014973.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163163030719.489837.2236069935502195491.stgit@devnote2> References: <163163030719.489837.2236069935502195491.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Punit Agrawal debugfs_create_file() takes a pointer argument that can be used during file operation callbacks (accessible via i_private in the inode structure). An obvious requirement is for the pointer to refer to valid memory when used. When creating the debugfs file to dynamically enable / disable kprobes, a pointer to local variable is passed to debugfs_create_file(); which will go out of scope when the init function returns. The reason this hasn't triggered random memory corruption is because the pointer is not accessed during the debugfs file callbacks. Since the enabled state is managed by the kprobes_all_disabled global variable, the local variable is not needed. Fix the incorrect (and unnecessary) usage of local variable during debugfs_file_create() by passing NULL instead. Fixes: bf8f6e5b3e51 ("Kprobes: The ON/OFF knob thru debugfs") Signed-off-by: Punit Agrawal Acked-by: Masami Hiramatsu Signed-off-by: Masami Hiramatsu --- kernel/kprobes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 790a573bbe00..1cf8bca1ea86 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2809,13 +2809,12 @@ static const struct file_operations fops_kp = { static int __init debugfs_kprobe_init(void) { struct dentry *dir; - unsigned int value = 1; dir = debugfs_create_dir("kprobes", NULL); debugfs_create_file("list", 0400, dir, NULL, &kprobes_fops); - debugfs_create_file("enabled", 0600, dir, &value, &fops_kp); + debugfs_create_file("enabled", 0600, dir, NULL, &fops_kp); debugfs_create_file("blacklist", 0400, dir, NULL, &kprobe_blacklist_fops);