From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 33E6741B360 for ; Thu, 9 Jul 2026 12:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783599526; cv=none; b=NWvfoe6QZ6rg8mjXKFXdSZ9fvbX8wCOk3hpC0lQ9GLhoyWVzkY4B/qkBmCiy10Ar1yPobXtCgWNE+XsnLc+4WJQ1sSVUzT08enywP+/ncLW6HVTPT2UuS4KyQPeYe+bbY31VfGpnW2XYzqzjvWxxJaQAgE3TLIdLYK1hNE+Ze3M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783599526; c=relaxed/simple; bh=XaaFaOM5GSvaUgQorJfaOxm5VOZhBRgjQkClYXbm02A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=blXGrIxn+Zd76GdeG5CQyqekq3UPQqQMfnjWor+oHu6g1UTGVGzW0cvouFASvfopVJ3o6QbHB1SHk3LpSW7K6qVe8NzlDAwXYwces5CSmWXgwylUlsHbSq5i/vG9pmZ/KpKaDwj4T4kTXtH5aVc4qbhrjS2Hh/cgsPi0E9DKEdU= 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=wP1oorKt; arc=none smtp.client-ip=209.85.221.43 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="wP1oorKt" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4728c12ba97so943905f8f.0 for ; Thu, 09 Jul 2026 05:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783599521; x=1784204321; 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=jngqR2jmiogEZ8PxklwH7MWgCBRAFgrXCWBq2O3HcN8=; b=wP1oorKtTYvNeXySfJNme3rS+TD2j3RPTkTQtbCJEnP5zNgArZk6q5ZT1LvFRlXg+k XtoGfiCcX0bYf2DnX7e0/rldxu0ID5DRx/QJRQ+p1CfH5J4tCkSDCcgvab/T4urXdCzD l+k5ZDkPZDLx6b8y65PBnBjACHUkWu0j6A3T7GjdqnffAGVm3v/CzbZ6YO/f5pKz38Rp h71Lf4/OiJkML5fIevRmUA5+sZ+AoT/yrJuV+nGJOu0mpYVaTWWuvgIWfzZ7W0A8cY4E 8oL5mFi5+piwaokuJVUl3e29FhyerhkLPcK1pm4UQHSnlVMb9duuzM9nKeJDq09a64Qf 7i7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783599521; x=1784204321; 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=jngqR2jmiogEZ8PxklwH7MWgCBRAFgrXCWBq2O3HcN8=; b=ab8FIgfHfA7r0sC/4irH2x77Ul4vuD0N6DlJPGmP6r7uKoUHHPzn+MhM5OiTmi6ZF7 mlakFiVY17eWS5wnE+7NfiEBLfZa7UuKDuizIQB+4rj9+O/aHCO2eplBlN5ZKZR1Vx9l OXlIBYWycrvll8eFlIKnBY+z0fXkhpNbzmWC6f+kskuL7vG/840HJZCnsPLhHGbcu61u LrCKP8hdvYPVuakmcDDCfqyQJRTA9AMerNJ0bq49+XzNpHF0A7oR23sWp9cq9AhKgR5l FXZVZXkUV+VnZVZsaOqMPpth9JZPttk48R8LAZCxYwdI8ljScVdyFXOeifNayTtVRhA7 DbQw== X-Forwarded-Encrypted: i=1; AHgh+Row8cHRt3sEwgX7+Z5HwhxiwZljq3QFX0roGb1UfXyv0ys+ATYoVOZXrE894McWUF3p8mjqPgcSvmjMtqU=@vger.kernel.org X-Gm-Message-State: AOJu0YzxorcZV59lU+UVmSMnw7fkIvgFWUYOLEORTKKzgixxOvdEvf60 cK7hro34C0csbt+oPch6Zh3DAF6JuTom+u235ztWCuy1nkAKMrq5CC2ihx8IV4yAxQ== X-Gm-Gg: AfdE7cmMjVc9TDmPtNZ5WA9c3psKzrtVi2zDtddsyVgn9lPYcWvNXvVrhXY4PMCjgNP I+xGnCiFduM8PPJJo5rT1T7Z+iK2EoBgYYrpp2Pl2/dNBLpiXT0Z0ffytm7na7DIlATT823VdgQ YC+R+KGCF/mx2OXr0rFGVOy92+2UC37Pqr/A3h2sLyhKO9r0b+SMtlnEY+3RglEClhIefu5jFbB 1DgAEQxQGNXIodVFRPIZx45JpLSDbOXOIBvzqUx5ZnXA1XxZRpI+/mD7UuQ8rhVL/TSCOZq7/3I gM5lHtEKw2QkRejx6Fn4KHLZDmCinUQnH1tMGg5Y3SB6S2Fcc+VGaJbKq8BKjkJhfkZxE05wnnL qz5rEf8hdXup4EGQH02l4Znu9kqWZanKfhhnUHffvSUg+rZ79rgbp4Ou4tZN2Do6XtYUOIDr0xX dFqP05qxM0dOKA0NBLpIhY+w6+Rgeqrj3V7ZSnTh4RXHeC74vNdraV40rC9JXwsA== X-Received: by 2002:a05:6000:40cc:b0:47d:eddb:c102 with SMTP id ffacd0b85a97d-47df076eb66mr7316781f8f.28.1783599521149; Thu, 09 Jul 2026 05:18:41 -0700 (PDT) Received: from google.com (137.69.77.34.bc.googleusercontent.com. [34.77.69.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1d910sm49755128f8f.6.2026.07.09.05.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 05:18:40 -0700 (PDT) Date: Thu, 9 Jul 2026 13:18:37 +0100 From: Vincent Donnefort To: Steven Rostedt Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, Sashiko Subject: Re: [PATCH v1] tracing/remotes: Fix leak in trace_remote_alloc_buffer() error path Message-ID: References: <20260708133201.295072-1-vdonnefort@google.com> <20260708125906.746f1def@gandalf.local.home> 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: <20260708125906.746f1def@gandalf.local.home> On Wed, Jul 08, 2026 at 12:59:06PM -0400, Steven Rostedt wrote: > On Wed, 8 Jul 2026 14:32:01 +0100 > Vincent Donnefort wrote: > > > If page allocation fails in trace_remote_alloc_buffer(), desc->nr_cpus > > is not yet incremented for the current CPU. As a consequence, on error, > > half-allocated rb_desc will not be freed in trace_remote_free_buffer(). > > > > Include the failing CPU in desc->nr_cpus before going to the error path. > > > > Looks like Sashiko found other issues you may want to address: > > https://sashiko.dev/#/patchset/20260708133201.295072-1-vdonnefort%40google.com Yeah I saw it, the dreaded "This isn't a bug introduced by this patch" ... Let me send a follow-up. After looking at the other issue, I think I want to slightly modify this one actually! > > -- Steve > > > Fixes: 96e43537af54 ("tracing: Introduce trace remotes") > > Reported-by: Sashiko > > Signed-off-by: Vincent Donnefort > > > > diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c > > index 2a6cc000ec98..62d3d431c309 100644 > > --- a/kernel/trace/trace_remote.c > > +++ b/kernel/trace/trace_remote.c > > @@ -1008,8 +1008,10 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size, > > > > for (id = 0; id < nr_pages; id++) { > > rb_desc->page_va[id] = (unsigned long)__get_free_page(GFP_KERNEL); > > - if (!rb_desc->page_va[id]) > > + if (!rb_desc->page_va[id]) { > > + desc->nr_cpus++; /* Free this partially-allocated rb_desc */ > > goto err; > > + } > > > > rb_desc->nr_page_va++; > > } > > > > base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda >