Skip to contentSkip to conversation

tracing/histogram: Fix UAF in destroy_hist_field()

PATCH Superseded Kalesh Singh 1 participant 1 message Nov 17, 2021 Tracing

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tracing/histogram: Fix UAF in destroy_hist_field()

Calling destroy_hist_field() on an expression will recursively free any operands associated with the expression. If during expression parsing the operands of the expression are already set when an error is encountered, there is no need to explicity free the operands. Doing so will result in destroy_hist_field() being called twice for the operands and lead to a use-after-free (UAF) error.

Fix this by only calling destroy_hist_field() for the operands if they are not associated with the expression hist_field.

Fixes 8b5d46fd7a38 ("tracing/histogram: Optimize division by constants")

---

Changes in v2:
- Handle all freeing logic in one place so we don't need to worry about where to free what, per Steve

 kernel/trace/trace_events_hist.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +4 -2
index 5ea2c9ec54a6..b53ee8d566f6 100644
@@ -2717,8 +2717,10 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
 
 	return expr;
 free:
-	destroy_hist_field(operand1, 0);
-	destroy_hist_field(operand2, 0);
+	if (!expr || expr->operands[0] != operand1)
+		destroy_hist_field(operand1, 0);
+	if (!expr || expr->operands[1] != operand2)
+		destroy_hist_field(operand2, 0);
 	destroy_hist_field(expr, 0);
 
 	return ERR_PTR(ret);

base-commit: 8ab774587903771821b59471cc723bba6d893942

Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog