From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 CAFB13ACA40 for ; Mon, 13 Jul 2026 08:21:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783930887; cv=none; b=ozw1vC2Mg4D1zcFRsegmoMRUErfxs7N+NRgrolZaoYMQlIIYoDxIZC+LHzIASWVgm8lWXV+lBET5H3T20PJZ2q8nIK/74g44BDw/v2J9j3M99y4C5ZlWQcwNKLB7q0a/UCrt9xA+n5DpXFueuDYeWHVMp9bYwuGlJMp0DpJWzyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783930887; c=relaxed/simple; bh=Yy0Rum6OX/7GHOu3/FJbCVc981c5QVNECD1+87yPWl4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sj34YBXy/I0ws28xzmt09loyyIUb3lyc1lKL6oZ/W610eC/WZwRAH4o2ygc2DD5fJkCmdup0S/y/Xz8QhUOldYK/l8JavaHbjipnfvAqWoew51MvYuch3Co5rzaeshj3FDfeDH08q+5UrgjIzaGvv4s+nCoR/Q3iN4A3claQngY= ARC-Authentication-Results:i=1; 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=e9YcDzZJ; arc=none smtp.client-ip=209.85.128.52 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="e9YcDzZJ" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4921eed3fa2so26551805e9.0 for ; Mon, 13 Jul 2026 01:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783930884; x=1784535684; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=YrAkZsSUgpZbjxzvPdeiOWzj9u/doeixQHc02MlsfrU=; b=e9YcDzZJghi5jXJVYT0my42/vYXRQbpJdQ+LQMitnRl0YczcPIIfGJVk2Y4s2zBclt iD1iQZB3N+6ZencgHVDZbbMiszOAF370/yp6ehSbClzHhdfHUHq2peDjM5OWpmMxKvgI oJwXVWGg5JLp/LH+nG/OcdqGL8NEEvTUl+Jn7PhnK5IS7ZXkj+P5/SqOzPDu8F+2pivg 9YJxI6Nl7Vkl2DlLKX/8PBg6SW6q4S5XnZdddBCDIZJck18MvvEhpUcotEXqhu2SLOY0 MgGW7X2wF/V7kJcnQMsQgLp4opnktGjcYgx57MS7bkQruY4qGrX7l/F9ccCt9qr4aON7 0rDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783930884; x=1784535684; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YrAkZsSUgpZbjxzvPdeiOWzj9u/doeixQHc02MlsfrU=; b=X8j3unrkHHvGr6QekRrzTY5gfmnaVO9OzVuUUP9HYP2LFBRMUcQ0MndKnF+iK2C6Ji h4R9IFWbWusK6Hhc6XfvdKNYYcZ3XCCNjTuSmCZc4bbWZ3K8CUc/cgJBNe8b0h29jTbN jfs1OCtR6Aj6beyeDGHiEfMO8soDgKWLwQ/SLppAEkSak12KUSveoWoSQ2NMlx+H+pMR YJWX6NCfl4yVGi8mKipFMHsWErKFAvDwUzC15M3xpXzAVFwF9nrHYH3kAS/RTxd9wtXE 3bhgtVNHGgXEjb37tFLRX4q2k8YGR2cD8g118Ay8+lHZzFRrgYexBT+UV6aOwGiwZCkh JG0A== X-Forwarded-Encrypted: i=1; AHgh+RoOSN+wsxnTnfjR++rGHjXsHrDGmr41zP5Tpal1i86V1PMG0MfryP2xchiy2UVxcoZYa5KEzEW8d/ZB6tQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwvFQ+1ZHAie66PKSBs4lnc3ZCTBjZOh6m9P3dSwp2OXo66Kgal IijioBvBN0Y8d3e1E6IgIXaOkv82i/eE7E8RIBVghcj/CqFJcSpLVojOMuewTjxv9g== X-Gm-Gg: AfdE7cmj28tooFPl708hkR7Is7LceOKvaj+XiRaeR4ou3YkB78P2DFfEcBuQYnNV3Ve vDAiw9UfR95WSP669x00QxAwf3/GU2/d7fJkK2lMiHNU1HvpgzEW18+kFT9C6kam+RnrbdJmx4i bbSvAB37vxqOGoNLRCiS6PWB1/fWERw7E+FUN1YCc8oZiIz+Gg2+7r8NObvAqjqO945UGMs+++V RbqdFIrbjqbFo2cdLqLDDmBrrwwaJ0IMjuK6chPjq4HBmX8QTFICZw3qPijkfi1imN0bpPrFixD s0TPqZE0AUTtaq7K7qwaLnLRK9kHsVRn6oycM1MuZB5/3jCt9uJIIrEspL6aKR6Quedgdjn5S6B MK+tj2RGvDgWyKsxQmV127oPHUdebuM4upkSwRW/95qwiCKdRv5MbUMiGI/gbLTjqiUmxHm5egI wdS6KAM3cVWtTzt4bAwsLfkhYRtAqoiN2BY7ewpfJiqgwI7sN0uuA= X-Received: by 2002:a05:600c:34d1:b0:492:58d6:2565 with SMTP id 5b1f17b1804b1-493fd45f58bmr58666575e9.25.1783930883028; Mon, 13 Jul 2026 01:21:23 -0700 (PDT) Received: from google.com (137.69.77.34.bc.googleusercontent.com. [34.77.69.137]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f4f09f89sm521553025e9.10.2026.07.13.01.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:21:22 -0700 (PDT) Date: Mon, 13 Jul 2026 09:21:18 +0100 From: Vincent Donnefort To: Fuad Tabba Cc: rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, will@kernel.org, tabba@google.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] tracing/remotes: Fix page_va[] access before counter update in trace_remote_alloc_buffer() Message-ID: References: <20260713072823.2668323-1-fuad.tabba@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260713072823.2668323-1-fuad.tabba@linux.dev> On Mon, Jul 13, 2026 at 08:28:23AM +0100, Fuad Tabba wrote: > page_va[] is annotated __counted_by(nr_page_va), so nr_page_va must > cover an index before that element is accessed. The allocation loop > writes page_va[id] while nr_page_va is still id and increments it only > afterwards, so every write is one element past the declared count. > > The store is out of bounds with respect to the annotation: a build with > CONFIG_UBSAN_BOUNDS on a toolchain that honours __counted_by > (clang >= 20.1, gcc >= 15.1) flags it as an array-index overflow. > > Increment nr_page_va before writing the element it now covers. A failed > allocation then leaves the slot counted but NULL; the error path frees > it with free_page(0), which is a no-op. > > Fixes: 96e43537af546 ("tracing: Introduce trace remotes") > Signed-off-by: Fuad Tabba Reviewed-by: Vincent Donnefort Tested-by: Vincent Donnefort > --- > I found this while reviewing Vincent's series [1]. > > Applies on top of Vincent's "[PATCH v2 0/3] tracing/remotes: Fix leak in > trace_remote_alloc_buffer() error path" [2], which fixes the other > issues in this function. > > [1] https://lore.kernel.org/all/20260710114819.2689386-1-vdonnefort@google.com/ > [2] https://lore.kernel.org/all/20260709160017.1729517-1-vdonnefort@google.com/ > > kernel/trace/trace_remote.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c > index 0f6ef5c36d84e..ef42d9c38b374 100644 > --- a/kernel/trace/trace_remote.c > +++ b/kernel/trace/trace_remote.c > @@ -1004,11 +1004,10 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size, > desc->nr_cpus++; > > for (id = 0; id < nr_pages; id++) { > + rb_desc->nr_page_va++; > rb_desc->page_va[id] = (unsigned long)__get_free_page(GFP_KERNEL); > if (!rb_desc->page_va[id]) > goto err; > - > - rb_desc->nr_page_va++; > } > rb_desc = __next_ring_buffer_desc(rb_desc); > } > > base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda > prerequisite-patch-id: 8bdd7b28f09e97cff4f5995196b83b377c961d8b > prerequisite-patch-id: 6781b7ce5156d229fd21a757ef0cd66dd76130cc > prerequisite-patch-id: 56bcbbdceddf4533770d48d1835d5b7e11f47d56 > -- > 2.39.5 >