From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1482233935 for ; Sun, 5 Jul 2026 19:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783278616; cv=none; b=VOUaB6QkDHHlQtobY9gU9bkSJygi/m4YLacgrt5en2aBW/nsnA9x60YMaabBD6sjnVuCRokE/oPTCYozTA6MYXSHrCGgFL4fvBkekCeeW/RVdskiIDw4yz+RGsNi1/MbI+d045oLlhSh78IxS5K3O/kt67tBmqmFzuMHSRggrgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783278616; c=relaxed/simple; bh=lJkMh7PaATeqBMJRKhUqmE7OtV1FEwJx87LkAhXbjpE=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=k6VFuI9JSDBHFE1hRVL06v93fOffImH2E+3p9++nab+pWTXi2Y7YL4rO0xPZOclQOQaHGAfp1TSGqxpt8W+hyMyxFwwa9w1WN3sFM8NhqsTM92QUUJEQ6mqBi2wI9BrKSNb5vn5FQ2QW53/Ygglf+MWgEeeQhW43MckYrTbfTho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=WPGXC4OL; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WPGXC4OL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D161F000E9; Sun, 5 Jul 2026 19:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783278615; bh=9BHDv+Rw4NzCieKk3X4LgK1gU+OZ1CiRkbkRDRFeaJg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=WPGXC4OLsAELrDqwtUzbUxgJzPd2XbK4t0hdHMyuov0yRbW3WHUnAvNdtixo3TEYF UVNjsCB61wPs/avgo4D4cfNBCqsvhdse0r9wzwZfsDD1LldYArUXcMC30UK60qVmv9 DV49uMsPa5qVWIUhW1xIJ/uuYWnzOoqi47kMf3MA= Date: Sun, 5 Jul 2026 12:10:14 -0700 From: Andrew Morton To: Bradley Morgan Cc: Feng Tang , Petr Mladek , Jinchao Wang , linux-kernel@vger.kernel.org Subject: Re: [PATCH] panic: fix va_list reuse in panic_try_force_cpu() Message-Id: <20260705121014.d783e021f38f262faf2404f2@linux-foundation.org> In-Reply-To: <20260705164123.18746-1-include@grrlz.net> References: <20260705164123.18746-1-include@grrlz.net> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Sun, 5 Jul 2026 16:41:23 +0000 Bradley Morgan wrote: > vsnprintf() consumes the caller's va_list. When the redirect fails, > vpanic() reuses it for the panic message, which is undefined > behavior. Use va_copy(). Thanks. > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -412,7 +412,12 @@ static bool panic_try_force_cpu(const char *fmt, va_list args) > * fall back to static message for early boot panics or allocation failure. > */ > if (panic_force_buf) { > - vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, args); > + va_list ap; > + > + /* Do not consume args, the caller reuses it if we fail */ Nice comment! > + va_copy(ap, args); > + vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, ap); > + va_end(ap); > msg = panic_force_buf; > } else { > msg = "Redirected panic (buffer unavailable)"; AI review found a possible pre-existing thing in there (as usual, sigh). Seems pretty improbable: https://sashiko.dev/#/patchset/20260705164123.18746-1-include@grrlz.net