From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 59A44383C6E for ; Thu, 30 Jul 2026 08:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785399196; cv=none; b=EL3G+DeIhcfYPz7KVab0a+ztg39J83FtDSWIj2IYA8O/0tegBj8mFBDgFXcCM4UNRB3Ne4QMgIBnYJ3Qu237qaO+CcaLDzb6xWATRUF9kHWgIZzBLnCQLdzaL7yJGZm/fUA1yIo/+xJ8Ce3SpXi2LDln7XPIILQbyAPWudI8SSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785399196; c=relaxed/simple; bh=4UjqegiqqkwQLGcObgsAsaBlVRRZB81Kadcu/mnixzA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j3zoDtVZxboRKfcelicaxlVuxbMEJZfk0rLIbdDTnkyoJD3ib0C4rNujR9h8Bh3patPjfbNrd3JhgCT3USyqA4tZ6mdE6dCwiPHk2X+i2wjgbpmRODF3D8/PyspAOrwY1kyd6OdDU1uDFkF+69qc4ey6Iwmj4KZakGpbMqrT1Ko= 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=WrIUkeki; arc=none smtp.client-ip=209.85.218.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="WrIUkeki" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c1740c36c5cso262434666b.2 for ; Thu, 30 Jul 2026 01:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785399194; x=1786003994; 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=t1c3TMYJPV/i4q6IntYhww97ey3M9wPjCcBpkAHl8jU=; b=WrIUkekiF4PwMAWt1KRA7pU8LgGz7qqWiaBPk5gkmyQQR5YQ6+mnk5u6lNH5qsgBPk BWW92j6lo32GWLnL2/TsdKhkKaNDG4Y4H7EsNiI8+GKiMXCM8O3r6xwzvs+VXb18Mw18 jqnvT3B4kL2rh+Sdcy+p+IMVpuIWJDeis4eILASrwfP6BZaSdRiHzcLpu75p2XxZnr3f WGp6ud5hxGRhR001p3oW19fwojZBpQzaDWXmNWknHnO6HR0Z8LzexgJOyjcs1qkFt2gL pyaX28zp7IHc+E/qMF3vDdrEh/qXDF3t5yiuNFkW58LrV7rpLlb4n3uewsraGpZzfxwQ u/zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785399194; x=1786003994; 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=t1c3TMYJPV/i4q6IntYhww97ey3M9wPjCcBpkAHl8jU=; b=h6WgPGDrHFe/z6NlkztTbRlkPdMRS7aqiTfZ8pAWbgVaNEsWLTnKD5iGKIclpF7kZo PXXxUet0h4muL9nNkK89KEXWuyu2M84yfh0aXK9hBXa5lnBLVKwwUkkZrTQQ+eDO5fPn Zp4uafOb4IfMY+P0zs+B5sBA8jsnIMai7F6HL1kLBVF39+W62rj/p56LK+gwegrkvm9X +XMaNp6WyWgZAFp08RZECk5G/g4o6Ov4EaiLdI2JbE5/4taAFFydEg0zHu3hXESKycxF gHw+jKpIo+lsQIflHkoCfC4smKfXkWsxa7cnz3QBwVIyoRxWoIF+JqDlKQZsQAyTaNrk ZUZw== X-Forwarded-Encrypted: i=1; AHgh+RoveGuHnuNjqzs8SZzmcf6wn8eAd+Ga/z+qdKNH7HEqRDy8nZrmmLrf8xraVNqullQO1hp75s/MK3rk5iM=@vger.kernel.org X-Gm-Message-State: AOJu0YybnQZl0bsrjRJiakiuvuOdFgKJogK68fmADNEgOwQK4xMKY6Ye JzVFjDsueVH/5y2WhuK6j0PAIVi0q/kvh4EB0jgmRZCtLzkWpHSeS4WbP49Hx/doLlV/ljXdfkw Rgrcbgg== X-Gm-Gg: AR+sD12lsonp2dFLBiSa//f4WUJYYSti7/GCnJEHdBs5uZ+SAcUOoAiA/OrYe1YC5tY ZOMNEjewfbjQQBl1mIj8CUDEHbLwzgWF0VwhpAySyPbu6DX9QGnZecYN4cCHzYH81cKA6+vrHdP RrbSgmUm/647LkDQT7cn7rrsCUdGcsrymJo6aCiErynDyIDqvvQF8ncSIm/VP57bQGvt2WhcByu XN8rcpAvcp/HuBt+O0Ahx1OqbDVOcUzawoLYLSbfNtLvqyY2ShLnH5i5SsXQnrPKyGmW80Zqlxq AdrPX32VJb6aXXdD+BHoY9TEniWL8pXqeGUueiOcWUrNDQBrc9hsTB6TuvcpAPVztjhc3AUazWp jUVKjMu5rc+JW/RhiqSVDb2Z/cTJRo8ZcN1UiZDi/PTfwDhz08xsA2i7ie9sqJgRNpVAv7ndKwp SaWPB8feYNfMZqDGineWLpxwfYMtJmBrNNUzXlnHeKt+tj4ju9j2+L+8EZVvelLFl9RQ2x/lKxW RkpGCNOT/L+1zevN2gJn86pUOK6glW5 X-Received: by 2002:a17:906:9f92:b0:c16:9ca5:e551 with SMTP id a640c23a62f3a-c1fa55d53c2mr81676266b.14.1785399193003; Thu, 30 Jul 2026 01:13:13 -0700 (PDT) Received: from google.com (135.91.155.104.bc.googleusercontent.com. [104.155.91.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1fa8577e6dsm37228166b.22.2026.07.30.01.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 01:13:12 -0700 (PDT) Date: Thu, 30 Jul 2026 09:13:08 +0100 From: Vincent Donnefort To: "Masami Hiramatsu (Google)" Cc: Steven Rostedt , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH] ring-buffer: Fix subbuf_ids memory leak in rb_allocate_cpu_buffer() error path Message-ID: References: <178539491147.180138.1181424244288838594.stgit@devnote2> 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: <178539491147.180138.1181424244288838594.stgit@devnote2> On Thu, Jul 30, 2026 at 04:01:51PM +0900, Masami Hiramatsu (Google) wrote: > From: Masami Hiramatsu (Google) > > In rb_allocate_cpu_buffer(), cpu_buffer->subbuf_ids is allocated using > kcalloc() when buffer->remote is non-NULL. If a subsequent page allocation > fails (e.g., ring_buffer_desc_page() returns NULL or rb_allocate_pages() > fails), execution jumps to fail_free_reader. > > While __free(kfree) automatically frees the outer cpu_buffer structure > at scope exit, kfree(cpu_buffer) does not recursively free nested heap > pointers such as cpu_buffer->subbuf_ids, resulting in a memory leak. > > Fix this by explicitly freeing cpu_buffer->subbuf_ids in the > fail_free_reader error unwinding path when cpu_buffer->remote is set. > > Fixes: 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes") > Assisted-by: Antigravity:gemini-3.6-flash > Signed-off-by: Masami Hiramatsu (Google) > --- > kernel/trace/ring_buffer.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c > index 78d3875a47a5..03f6baf6a5f5 100644 > --- a/kernel/trace/ring_buffer.c > +++ b/kernel/trace/ring_buffer.c > @@ -2599,6 +2599,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu) > return_ptr(cpu_buffer); > > fail_free_reader: > + if (cpu_buffer->remote) > + kfree(cpu_buffer->subbuf_ids); alloc_cpu_buffer() being kzalloc, I suppose here we could just unconditionally call kfree(cpu_buffer->subbuf_ids) ? > free_buffer_page(cpu_buffer->reader_page); > > return NULL; > -- Vincent