From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A620D3DEAD6 for ; Wed, 5 Aug 2026 21:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.160.169 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785965402; cv=pass; b=QfNEL4Ax379Yp5qXE0tnmHEhH314PnOSZqzjsHQbZTSJsL4gAVz6ciRbssNu+T4NIbq2gSP5trYBcWLZl83jdIfKwUVpzOEKQ/HsmXGq8ewxzRd8qz/5BIQtFtEy2MqXiE0TDawYqs4b6KDEIDh43gAY+TqzZ2YT46+r3clXqaM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785965402; c=relaxed/simple; bh=D9Q/Au9Y+diFkozFMMx78S88MxEV5ROAubO99EyLbdA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=P0R7NUPBdAu1+IPV+agdcVsVgNa3vROCItYR8Ytr1JtlDUfK7+ZmYE/W7XZnRex8fsJ+vnY97QeS7sORWO/ZhaJ//TA8UAXOI3KMBmaIVYjcguC2Q/KfL+NCp8/gmoGCO32XO9pIynSxERyZY/I08QfbFzjzJAG9ZiUlKJe5Q6s= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=plDlIgE5; arc=pass smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="plDlIgE5" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-51c10e86e52so30251cf.1 for ; Wed, 05 Aug 2026 14:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1785965399; cv=none; d=google.com; s=arc-20260327; b=W12azIHFydbldlhx/Xuxlm7tQX7fmQ0TzTcZbrW0BQvQtDn/jOH//LYUBoJlg9KIQO YNVeC/aJINwd2y5I3bd9agsZXLHFfaOhJU7w9jLYsd0RG77m1wVpLsN3oKj0vPYmUQZ1 hukDJy69r2ndG4e7Digczk7cLJpqJE/h25dh5NW2G/Ybm7P/e7ip+OYfuhWGkBBxpK52 WdqEuIsAZEy9nsZ8eTeI+XywNm2ioKjdLAP4/ZOY1pilgnk+YFToEts0q3F8A4F3/k8z My46dLiCQeFj6WS7/63o6c1easrB4SW1uz4GuNsKXhYeoC4Prt/GbtmujABep6ie6g27 zhGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=O6Jb8l8BkMvXRyue7sGwCsNPEFPsZOpcTjt6skahsWo=; fh=sLTeVKpJi/EtIBooNSXhKsvseGYCxJ5WW8Sm98YXWnk=; b=T2W+u67aiQEGkdkoYPSACqRUjhhF6t8sem+B1Z+Bmg6XvJ5KF15Z9IJmcO50+7dsYx Qdks2MHaWw/AwmbfOD8DhYv419IEDDBxLrkw/dBhg5HNxI+k3SAyD8cF/Qx0V9pKHy5w mOtxa34Ha5EZIjKb6adhtLTiPvZaw7XYa4Z2SKxwlJdiy9UegDzncpji1zRIdWzkFX6a H/oHkP9ka3AkocrdcALCJp8VRwgsquoSDRS/7lz/32cT8FFufggxTmTFoI5SOnRP3aEj 0RoKjmLc/I9chnPSpW3AINFcKm+D96qb+sX2CNOJGwlPA4bbkzL8WlzwAP3ecSkTtTUP x0YA==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785965399; x=1786570199; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=O6Jb8l8BkMvXRyue7sGwCsNPEFPsZOpcTjt6skahsWo=; b=plDlIgE50Ec8inpkfWgYhtM/bLqDGCQLsjno4gdE3OTjIsrEJ6pHLVhpWOM0rrJgy/ ImmwEBNohzRm9TQ9vLi4besQ5nQt/wArpjgiDUiKXhWmqAfojyr6xgZQx6KT4wkOm3eY kV4yD+3fSgZTeq7iU+VCEO/79UcRzK3TY8KWFD5ZdSzmY1K6ipXsFSgzWYyMJqwpKF7q OGExFznvy5PCIDSLUVYpeM1B8rdycB9jZDxaw1s7A1gWlRzYsSX1DAjcHf8Yg626DU22 2XqXwoCqbXt6qvHwiVgj6zJATYtIta6ZmR3AYfFcrQr5dYNc/VwaowKFvWWioPv5yAFp 0QzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785965399; x=1786570199; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=O6Jb8l8BkMvXRyue7sGwCsNPEFPsZOpcTjt6skahsWo=; b=TUUAGfe3md5SINPvfbJBWHxZb38y0L//GH2th5eYOsHhp7wZAhKetCuoA0a/UhoM9N qnuBMqo4dXVWoAnOc1tTOHcvG+Z2croX5XytwTJq+or+dwkhMkFHDfakuOqIwJHfYX9w BBdSMX7K+X1fLesx6cAidTbgjpaLEHGLukKnVG06+n6leVCNwVz9yZP86QC5P4I60u58 Na0wRnK+oGM+UoQU2naM+WikrEsqDMndOwYXOrKltqgF94hIteaF18tk4vYtleBDK/dQ ysris8/WKDp3RMjnvX2NnZx73WM96NZ5unf2iKwiri8NVuf8iT+a4EaWS9MWXG4wd8CO uYgA== X-Forwarded-Encrypted: i=1; AHgh+RqhK30nwOK8TLd7+FVwSQxikfVAyu8XivG7JkMirQsUg6RwN79gYJPXFk6I8lVNy37xw1Zd/a+S1p5qxB4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1OfC6F+phqXicK4ySgsGBk3de21IMSEAvDad7GnnU523oIGEl IW8FTB7o56oC41aspTLzx08GytJGwoL5prkfEWcKLxYetC1ZCDFRKcNnHcSI2O9ebdM6wmuP85/ kvcd5ogvdIhNiWwNIiHKplArQO7VO6fwpB8jek06J X-Gm-Gg: AR+sD10FqjExiVfDzA3gDjB3klTrrsYreDE/dNW7smj8t9UdgiSxq7hi597coy+aDl3 qBVBmJNv8E5il1mPWeUUBz8yEVSNaOgmrg0PlEQ9drr3IgbckghMJIuuIaxxZp83VO5YZ8IkC8s TgynEkQumFfP1ufYUFBGRPf/ZoiIT4ab47ERCy9mKNyojqnrff1aQTFeKwAxS7Fkm1uFwG3MI1X ljM1PMLxHfT5bs7hUS1A09Moby1E5CT4LNQZ57uvse3EqpdKvyo84ND6vzGDwA93ZK5BD5jEqrB 1sNuIfdMkHp3puK1BucdjiAWOp8uDdGybvPLHmCdZbBlAQ== X-Received: by 2002:ac8:5a4e:0:b0:50f:af60:3496 with SMTP id d75a77b69052e-52cfe8205ccmr417321cf.1.1785965398780; Wed, 05 Aug 2026 14:29:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260805133013.235016-1-acme@kernel.org> <20260805133013.235016-6-acme@kernel.org> In-Reply-To: From: Ian Rogers Date: Wed, 5 Aug 2026 14:29:47 -0700 X-Gm-Features: AUfX_mxp6JglIFeFuC1xB1oBxKRPrPEploUrJuAEi-MbEygz0sPkZeGhJgqeO-A Message-ID: Subject: Re: [PATCH 05/12] perf jitdump: Check snprintf return before computing header size To: Arnaldo Carvalho de Melo Cc: Namhyung Kim , Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , sashiko-bot , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 5, 2026 at 12:45=E2=80=AFPM Arnaldo Carvalho de Melo wrote: > > On Wed, Aug 05, 2026 at 12:07:23PM -0700, Ian Rogers wrote: > > On Wed, Aug 5, 2026 at 6:31=E2=80=AFAM Arnaldo Carvalho de Melo wrote: > > > > > > From: Arnaldo Carvalho de Melo > > > > > > snprintf() returns the would-have-been length on truncation. When th= e > > > jitted filename exceeds PATH_MAX, the unclamped 'size' value inflates > > > sizeof(event->mmap2.filename) - size into a massive underflow, causin= g > > > the header.size computation to write an oversized header. The > > > subsequent write to 'id =3D event + header.size - idr_size' then corr= upts > > > the heap. > > > > > > Clamp size to PATH_MAX - 1 after snprintf in both jit_repipe_code_loa= d() > > > and jit_repipe_code_move(). > > > > > > Fixes: 9b07e27f88b9 ("perf inject: Add jitdump mmap injection support= ") > > > Reported-by: sashiko-bot > > > Cc: Stephane Eranian > > > Assisted-by: Claude:claude-opus-4.6 > > > Signed-off-by: Arnaldo Carvalho de Melo > > > --- > > > tools/perf/util/jitdump.c | 6 ++++++ > > > 1 file changed, 6 insertions(+) > > > > > > diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c > > > index 078d3304d2b7ebce..fd11e07bf00b7978 100644 > > > --- a/tools/perf/util/jitdump.c > > > +++ b/tools/perf/util/jitdump.c > > > @@ -493,6 +493,9 @@ static int jit_repipe_code_load(struct jit_buf_de= sc *jd, union jr_entry *jr) > > > jd->dir, > > > nspid, > > > count); > > > + /* snprintf returns would-be length on truncation, clamp to b= uffer */ > > > + if (size >=3D PATH_MAX) > > > + size =3D PATH_MAX - 1; > > > > Given the recent fixes to reading /proc/pid/maps where it was assumed > > the file paths would be limited to PATH_MAX and it turns out that > > PATH_MAX doesn't really do that and we had potential buffer overruns > > during synthesis, I wonder it would be more intention revealing here > > to use "sizeof(event->mmap2.filename)" rather than PATH_MAX. Other > > than the constant used, I agree with the change and using PATH_MAX > > isn't wrong. > > We need to go on having our tools/perf/AGENTS.md with all those rules > :-) Yeah, I don't know of a plan for AGENTS.md files but there is always: https://github.com/masoncl/review-prompts/blob/main/kernel/subsystem/perf.m= d Perhaps we can add something like: ``` ## PATH_MAX avoidance The PATH_MAX constant isn't a limit to paths in places like /proc/pid/maps, and reading paths from these locations can lead to buffer overruns for buffers sized at PATH_MAX - as such prefer dynamic memory allocation for paths. When referring to the size of PATH_MAX sized char arrays in kernel system call and ring buffer data structures, prefer to use sizeof the variable rather than the PATH_MAX constant to make it clear the size and possible truncation is being enforced by the kernel which may substitute long paths with the value "//toolong". ``` Thanks, Ian > > Reviewed-by: Ian Rogers > > Thanks! > > - Arnaldo > > > Thanks, > > Ian > > > > > > > > size++; /* for \0 */ > > > > > > @@ -623,6 +626,9 @@ static int jit_repipe_code_move(struct jit_buf_de= sc *jd, union jr_entry *jr) > > > jd->dir, > > > nspid, > > > jr->move.code_index); > > > + /* snprintf returns would-be length on truncation, clamp to b= uffer */ > > > + if (size >=3D PATH_MAX) > > > + size =3D PATH_MAX - 1; > > > > > > size++; /* for \0 */ > > > > > > -- > > > 2.55.0 > > >