From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=216.40.44.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796408500; b=hckXa+qDH+htp+12DjW/8HgTRUTMMHrYqw1HhrWk/T9V1eVDdlGOyBJ+A9Dn92V9Sz4V frKaky8QRXQVGpKLiSy0njqEnsExr9B0RUO4hS6tRUugs+EMABqcnW+Kc7WF2pGbP9SsP H99NURzEVvSKpmVDV4Nk8X8L0WuV2jaq5UwPELEWESrcYjzHvSNYpg3fM9igfnv4umfX/ MKpFBNhQOFDjk0s/k1cdrYFN5rYUl9fA4CT6GouUyr2ihlm8YgxEl8uzXuLiiR2tdKEK2 vloaZOLUYSVB55K1i8tmbY00EeHa9O51Emvmj8RlnIymZdLsLCM6he6aM4a8BvhgAaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408500; h=DMARC-Filter:Received:Received:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Stat-Signature:X-Spam-Status: X-Rspamd-Server:X-Rspamd-Queue-Id:X-Session-Marker:X-Session-ID: DKIM-Signature:X-HE-Tag:X-HE-Meta; bh=gLjjdsEdv0Pbm4XVEchsCcS33KJOkMYFO99PXOHQR40=; b=IQF7P1Mkec8XzS6/v9OtBVPCtePtLJIgBSTFMDaHN1Vhk72EPUmnuiwQh/qa1D1fOmOf nTv0lyKFTRVpK/y2TJrTBhiYEmJ3wEqTJZCaeDZlFEW+FBIHrPa5rFB3Ym8f631qnJk7V j4qjVITs42oleYMtEsE8SbdBOd335Blye8+pXWkpRriSagYnoCf8qBLZtm/9s4nBXWvCR F0Cxdvb9TEYpVXjC1G+sOtsr/71YG7ZI4JWgkuUscVSytRqyJk16HhNm8hqYq/LtrTiYG 5CiikR9KrWw4RJTEI6c81tMUc9EK+/l5BhlUWBseDWHirwGyZa7ryC89kOtjzjxfDNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; dkim=pass header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=NC4WEK61; arc=none smtp.remote-ip=216.40.44.14 Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B13C606A322; Fri, 4 Dec 2026 18:21:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7B13C606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=NC4WEK61 Received: from omf16.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3F43E1403CC; Fri, 4 Dec 2026 18:21:32 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf16.hostedemail.com (Postfix) with ESMTPA id 905102000F; Fri, 4 Dec 2026 18:21:30 +0000 (UTC) Date: Fri, 4 Dec 2026 13:21:29 -0500 From: Steven Rostedt To: EisenWalds Cc: Masami Hiramatsu , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] tracing: Fix sanitize_field_type() overlapping strcpy() and word boundary check Message-ID: <20261204132129.2fa853a5@gandalf.local.home> In-Reply-To: <20261204163630.17660-2-aerovynqueque@gmail.com> References: <20261204163630.17660-1-aerovynqueque@gmail.com> <20261204163630.17660-2-aerovynqueque@gmail.com> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: t5w7qcf4wt3tzndne9ajdfii5hxd43yz X-Rspamd-Server: rspamout02 X-Rspamd-Queue-Id: 905102000F X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX18LmcvnDYfh9WYn71KaTPiFb/qr/h3quTA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=goodmis.org; h=date:from:to:cc:subject:message-id:in-reply-to:references:mime-version:content-type:content-transfer-encoding; s=dkim1; bh=gLjjdsEdv0Pbm4XVEchsCcS33KJOkMYFO99PXOHQR40=; b=NC4WEK61oQM/KhghGNKUNk2xjZOKrjnbnurvBrttUVvsg1iNKvusto8lelrZNNPU/cJ6/TxktxAzdmVaR5xD1/vK4YCXXv6GQw2jgL+zdi6NKwdsajQxK7+8qo9lAtjBanXYgnYkNV7PMsUfAf/Cgg53pZzvkOojbTwgtrR9ak8= X-HE-Tag: 1796408490-833022 X-HE-Meta: U2FsdGVkX1+OBu9bIodQqH/j1iQ7dO/mNk1qaTg4Emq/wBlvTaDfb1FXmA/C50wCEWRDLuUm9fz5GYkAUQcnDKlLDI56cFrorp87wvL+F5QkCamT7qzspXn5Ps4HTK3NM+d9e2vTQ22j6TxA7Siqw7WB1JeW7Df0QZ8HF3Aq8L35MTYetqlHHcE+DT3y30B4ChZfFSYv2v5/S8ebo8/EuX+JJGoqqOEyh0sNnLS3+bShRQv+kpyiTCrQEY5lesV2PHXcyG67Wtzo7B6z9bMu/huAIEimpogdPFTkFhTZRw+8lPInG6yxrjtDYQAvOTm/ZBAXMOGce5YhGdCrrjvIdjGnspmQXfs8 On Fri, 4 Dec 2026 23:36:30 +0700 EisenWalds wrote: > sanitize_field_type() removes __attribute__((...)) from a type > string. It has two issues: > > 1. strcpy(attr, next) is called with overlapping source and > destination in the same buffer. Overlapping strcpy() is undefined > behavior per the C standard; use memmove() instead. > > 2. The word boundary check used isspace(attr[-1]), which skipped > attributes that follow punctuation such as "*__attribute__((...))" > or "(__attribute__((...))". Check for identifier characters > (alnum or '_') instead, so those forms are sanitized correctly. > > While here, compare against the buffer start (ret) instead of the > moving search position (next), so the previous-character check is > skipped only when attr is at the very beginning of the buffer. > Also cast to unsigned char before isalnum() to avoid undefined > behavior on signed char. Ug, more AI slop :-p Is there an event with a field that requires this change? > > Signed-off-by: EisenWalds > --- > kernel/trace/trace_events.c | 27 ++++++++++++++++++++++----- > 1 file changed, 22 insertions(+), 5 deletions(-) > > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c > index b5cbdd31c..d7637eb08 100644 > --- a/kernel/trace/trace_events.c > +++ b/kernel/trace/trace_events.c > @@ -3605,8 +3605,19 @@ static char *sanitize_field_type(const char *type) > > next = (char *)type; > while ((attr = strstr(next, ATTRIBUTE_STR))) { > - /* Retry if "__attribute__(" is a part of another word. */ > - if (attr != next && !isspace(attr[-1])) { > + /* > + * Reject if "__attribute__(" is part of another identifier, > + * e.g. "my__attribute__(" or "_foo__attribute__(". > + * Checking the previous character is enough: alnum or '_' > + * means it is still part of an identifier. Other characters > + * (space, '*', '(', etc.) are valid because C allows an > + * attribute to follow punctuation, e.g. "*__attribute__((...))". > + * Do you even understand what the above says? > + * Cast to unsigned char to avoid UB when char is signed and > + * the byte is non-ASCII. > + */ > + if (attr != ret && > + (isalnum((unsigned char)attr[-1]) || attr[-1] == '_')) { > next = attr + ATTRIBUTE_STR_LEN; > continue; > } > @@ -3618,12 +3629,12 @@ static char *sanitize_field_type(const char *type) > attr = ret + (attr - type); > } > > - /* the ATTRIBUTE_STR already has the first '(' */ > + /* ATTRIBUTE_STR already contains the first '('. */ Useless change. > depth = 1; > next = attr + ATTRIBUTE_STR_LEN; > do { > tmp = strpbrk(next, "()"); > - /* There is unbalanced parentheses */ > + /* Unbalanced parentheses. */ Another useless change. > if (WARN_ON_ONCE(!tmp)) { > kfree(ret); > return (char *)type; > @@ -3636,7 +3647,13 @@ static char *sanitize_field_type(const char *type) > next = tmp + 1; > } while (depth > 0); > next = skip_spaces(next); > - strcpy(attr, next); > + /* > + * Use memmove(), not strcpy(): > + * source (next) and destination (attr) are in the same buffer > + * and overlap. strcpy() with overlapping objects is undefined > + * behavior according to the C standard. > + */ > + memmove(attr, next, strlen(next) + 1); This is probably the only part that I may take, but unless you do this yourself with NO HELP FROM AI, I'm not taking it from you. -- Steve > next = attr; > } > return ret;