From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796402205; b=ugGHYtMq22QxLISqDz5Nepbg4BiLMv/ptsbTgA8ZjenPvGkeP6F1rvmZhfHyp4IDCj55 dY1gvjq8fVuKe8cAAJDpFZuVlPy80wF+GMbAmGXIwfQH8ljPnQM2U3eudaBX7RkHyfVGq vFsy7DtlBBqFssObywS1W+m8I5/Lbbm15Nb2EYhLVi6XgsQ0XZhltKwXWfgBjO7Dw8MeA WzNR/j55PLiUQPXPfiyYowsM220QYmUgJXtHUINpVy+YeIFbXr3e+kERjx/1ko6q9+w2a 7+7QH0voAg6XVAKz09WD0NO5hATLYuRAHAafv29Yf125vXtey4hbLNwT4vt+I5ywlcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796402205; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=PcdVProE6HoNxl6UvblAFi9AKM+hQjTJsk4vMa52zxE=; b=H3CiwEGpD4aVIBgAL+6gakLrjs57VbCxZ/uMpLCs56fjUm8iBYQNpyD/LZRjp3RmO954 RmqKoZISZLXN7ZZwkyKNqIRKr4wCuj661QTKiH3WuaHfXx3jlYkRRskZx+tp/GDg6tewQ hCmVIWY1Jzb1dc26JWlx7ZG4t0D50FNKGeXZSova30UP8/yu15FJwswB54mhNp+kUm4xS WESNt9ekBt4MYr+KOsNmBIA7hjKpYxXucDovAeihX5kFIV9uYf1enBir81Xj7HnxFibwn qb6pupCH/3GSn9gCrwVKTdHzlrpzoDAjZJWq96U6dNDlaSqNU5EhYX7g8dtDmJfnV4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NAyCdeeu; arc=none smtp.remote-ip=209.85.216.53 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E053C606A335 for ; Fri, 4 Dec 2026 16:36:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E053C606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NAyCdeeu Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3b5e015ce05so632841a91.0 for ; Fri, 04 Dec 2026 08:36:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796402204; x=1797007004; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PcdVProE6HoNxl6UvblAFi9AKM+hQjTJsk4vMa52zxE=; b=NAyCdeeun839mdT4mnvcHfDG/JBHwz8/7MtEW/GsuyYt8ClMEjPjfZ6VN9ePn7qL/x G5ImYUkhVvVlvkwd56Wp0kf0NmnK2R65wpUkqSbzAZxfnvmdlygYZQq6595CQgI7tyUa CdxMxuRZ8fWsZjVIrlhIUgh+vUEQDGmJu/awXzzUM7ZZUj4g5fOXn4it7zGHoXDV4iyN twMAqSnA6I6j2wZVeCzI0qauVTN/khHfI8blBOklr/Dlz+L4ePZ6OWDp6BLhifcewKmX c1/HK+4bmVddgI3NdleS2GC1MbOZalwL65TougmhRunz3YLoyvL0q13m3CtjsvpphUm5 9YNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796402204; x=1797007004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=PcdVProE6HoNxl6UvblAFi9AKM+hQjTJsk4vMa52zxE=; b=wy+KoJJhz3L7ssN6zRT+bmv127F+wD/2/0u0c4NXZN3u7r1L2xTjPD/Paju1KKjmE0 pWXJ+WoOnys0HTtoZzgG8CkNAQRntkTOavoJysP02e3fT62ONzxtWvifyefI+zF5Vtua orVzeGiJZhYxbX+NzCEVbjE6733wudm6tv/LoFRZdKqbZs/UnshHN2YD9gwnMm/MLFpO DfFxCHChdnCuY/XzM7hryQ2u2jIspBoDQPIK2f5KYBjfmXyNMK/u+tFVO1DR0jcUruwy t3Pqva7aXfXzA0YJ1kV8H2m9zf20WthvzEMIvX3E0+NWReTdoJ29kMZfqhFo2ed2yE73 J4rg== X-Forwarded-Encrypted: i=1; AL+hErFDhZ9/OlLetwx/pAB0/ARqq4V4r+WAJOKVfXYee9beRiu0bwPOmP7/YZrLy52VtF1AxxpQE0zD/NOPy9o=@vger.kernel.org X-Gm-Message-State: AB4q+uHfGsPyED5xCSLoySK3lxAf9797GP3FmyHz07Yeob8cCFHVIUg1 HFaEmlda1jf8S8B1G3nuVhFCCHfWT4cbHqnsHcC40+JWe+ExTaN1F1eQ X-Gm-Gg: AZFdTZcTkCnTFkLJ9iAbY/0cbUrjhFDPjOkn/103RUGJ0dnIx57ZomnaDA439y+S3FB XVfRM1AY3ubMT9UXweu9tmHkz/uKtFAfD6t/xzo5MuWxJp6kh8CCzoaOLIKo+Dj02KyI5tSjLpn MX4lG+GYVrszNmoWeRn15HNORFWE3UB+DaYs4Mcnc0trP3T4H/WWH+gE7SlIut65qBmFRNdspsw h3VG2x5nObs2J1LgvrwYWlbpzjtOMaTji5lmD7XLuCKtS3DkvckoQJCpIUd5z9kg5bfFCUBX0P3 rjI1l9qGoAfpMrF/otEphxriliW6jSIFJMb2NgSRx1+4D2NPyOh7o4Rcg7zZAc6gWkN6HhrtcBy BTn4qcufPTaBG2RbzZ9BqmMMx7R3OKA8BmlQkPN5WBWzRvBzc0OLu2bUog7/Uia5Rs9ym977dub vmX9qHHRlWvTzjhILgKO6MLZV78+Y6mojrHW01IG0Z3CsKyOSoiKxgsYhurbnMU5GNnnPpXGKLl 4mk3yGgm9MDb+VhdKLvEfv7OtsshmKvTCtqWEuXKyRH/J5u4h5wdJt3Xsw1diANrBaleE679DRB 7HSn5SuL8cfU9X1/hcpDf6gFOVN40B3z5tGW7ynVcWasBP0= X-Received: by 2002:a17:90b:4ac3:b0:3b3:bd07:6646 with SMTP id 98e67ed59e1d1-3b5e06a46b0mr2462047a91.52.1796402204024; Fri, 04 Dec 2026 08:36:44 -0800 (PST) Received: from localhost.localdomain ([165.101.49.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc35aecsm4682299a91.9.2026.12.04.08.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:36:43 -0800 (PST) From: EisenWalds To: Steven Rostedt , Masami Hiramatsu Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, EisenWalds Subject: [PATCH 2/2] tracing: Fix sanitize_field_type() overlapping strcpy() and word boundary check Date: Fri, 4 Dec 2026 23:36:30 +0700 Message-ID: <20261204163630.17660-2-aerovynqueque@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204163630.17660-1-aerovynqueque@gmail.com> References: <20261204163630.17660-1-aerovynqueque@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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__((...))". + * + * 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 '('. */ depth = 1; next = attr + ATTRIBUTE_STR_LEN; do { tmp = strpbrk(next, "()"); - /* There is unbalanced parentheses */ + /* Unbalanced parentheses. */ 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); next = attr; } return ret; -- 2.56.1