lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231130234048.157509-12-lb@semihalf.com>
Date:   Fri,  1 Dec 2023 00:40:44 +0100
From:   Łukasz Bartosik <lb@...ihalf.com>
To:     Jason Baron <jbaron@...mai.com>, Jim Cromie <jim.cromie@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Kees Cook <keescook@...omium.org>,
        Douglas Anderson <dianders@...omium.org>
Cc:     Guenter Roeck <groeck@...gle.com>,
        Yaniv Tzoreff <yanivt@...gle.com>,
        Benson Leung <bleung@...gle.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Vincent Whitchurch <vincent.whitchurch@...s.com>,
        Pekka Paalanen <ppaalanen@...il.com>,
        Sean Paul <seanpaul@...omium.org>,
        Daniel Vetter <daniel@...ll.ch>, linux-kernel@...r.kernel.org,
        upstream@...ihalf.com
Subject: [PATCH v2 11/15] dyndbg: don't close trace instance when in use

Don't allow trace instance to be closed when it
is still being used by at least one callsite.

Signed-off-by: Łukasz Bartosik <lb@...ihalf.com>
---
 include/linux/dynamic_debug.h |  3 ++-
 lib/dynamic_debug.c           | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 56f152e75604..5555857d9ba5 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -186,7 +186,8 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
 		.filename = __FILE__,				\
 		.format = (fmt),				\
 		.lineno = __LINE__,				\
-		.ctrl = { .flags = _DPRINTK_FLAGS_DEFAULT },	\
+		.ctrl = { .flags = _DPRINTK_FLAGS_DEFAULT,	\
+			  .trace_dst = TRACE_DST_MAX },		\
 		.class_id = cls,				\
 		_DPRINTK_KEY_INIT				\
 	};							\
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 43e94023a4eb..73b6818e5fab 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -81,6 +81,7 @@ struct flag_settings {
 struct ddebug_trace_inst {
 	const char *name;
 	struct trace_array *arr;
+	int use_cnt;
 };
 
 /*
@@ -274,6 +275,7 @@ static int handle_tr_opend_cmd(const char *arg)
 		goto end;
 	}
 
+	inst->use_cnt = 0;
 	set_bit(idx, tr.bmap);
 	v3pr_info("opened trace instance idx=%d, name=%s\n", idx, arg);
 end:
@@ -296,6 +298,14 @@ static int handle_tr_close_cmd(const char *arg)
 
 	inst = &tr.inst[idx];
 
+	WARN_ON(inst->use_cnt < 0);
+	if (inst->use_cnt) {
+		pr_err("trace instance is being used name=%s, use_cnt=%d\n",
+		       inst->name, inst->use_cnt);
+		ret = -EBUSY;
+		goto end;
+	}
+
 	trace_array_put(inst->arr);
 	/*
 	 * don't destroy trace instance but let user do it manually
@@ -316,6 +326,26 @@ static int handle_tr_close_cmd(const char *arg)
 	return ret;
 }
 
+static
+void update_tr_dst(const struct _ddebug *desc, const struct dd_ctrl *nctrl)
+{
+	int oflags = get_flags(desc), odst = get_trace_dst(desc);
+	int nflags = nctrl->flags, ndst = nctrl->trace_dst;
+
+	if (oflags & _DPRINTK_FLAGS_TRACE &&
+	    nflags & _DPRINTK_FLAGS_TRACE &&
+	    odst == ndst)
+		return;
+
+	if (oflags & _DPRINTK_FLAGS_TRACE &&
+	    odst != TRACE_DST_MAX)
+		tr.inst[odst].use_cnt--;
+
+	if (nflags & _DPRINTK_FLAGS_TRACE &&
+	    ndst != TRACE_DST_MAX)
+		tr.inst[ndst].use_cnt++;
+}
+
 static int ddebug_parse_cmd(char *words[], int nwords)
 {
 	int ret;
@@ -447,6 +477,7 @@ static int ddebug_change(const struct ddebug_query *query,
 				  dt->mod_name, dp->function,
 				  ddebug_describe_flags(get_flags(dp), &fbuf),
 				  ddebug_describe_flags(nctrl.flags, &nbuf));
+			update_tr_dst(dp, &nctrl);
 			set_ctrl(dp, &nctrl);
 		}
 	}
-- 
2.43.0.rc2.451.g8631bc7472-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ