From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 59558255F2C for ; Tue, 12 May 2026 08:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778574096; cv=none; b=t5uxqM0E3GKRb6MI/IyHZwh8GqM+Bqz0xSFq6tQjVfTGfYcuca2VsIPNLB9ekzafHOkYKZU5PkdIFMIwSjxhP/RSRj71y7G1ezWoSol2s+Ha+gItUuOwF6/2TMS80bRLlIRXsT9sjDI5ufegxgbXaCsYHMru82tl7X8jxYzmOIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778574096; c=relaxed/simple; bh=S0c8l0KVzi9gFkfqKaRogVnJ6mPO0mScQwH1sYke9Mg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kd0+3AVGrkw74TlIUQahyjzKbcL9hORpf2ZKS0fugPjHeMboRkUjWcm5yx/HRRqDrs1djBhM6VhlyrvGexNPvNJfgEftS7ft1yYFJkq2D9FwQeQQf9jivkorR1sOYIRMWtxpmgLmGzwQ/WutAg/nazqWNQtAY5MPJccSFNY+Jc8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HU8uvc6x; arc=none smtp.client-ip=209.85.221.50 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.b="HU8uvc6x" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-44e5624c053so2897035f8f.2 for ; Tue, 12 May 2026 01:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778574094; x=1779178894; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=q3CO0P33u84+scWxvorwCoGWLliF7I5j4WDQyYtcSH8=; b=HU8uvc6xgdUqTQXujIn/X9wCF7auaZbJj3QlK+5bjOCRkw+DkMgR/nTCWXFkXKB8ic vr+3QM7R+xk2XYEe/l1XZTzvabs916Gtpk/Z/LpgRUW7Ge/dBHLgGwGlOQDR3d0oRw5X CTBd3vbcSiRwPSqPjqpZmmIHnthn047G+9wW+euBqFZOYpfqKVCId9rKj6sdSzt4sH7G eUvPKvpIk3+VLOZzNU6kcwx+2pJdyD2lop0YLfpMinugPfk6qzmQJw9Qv8TuJAj4M1on ml1eV4lJ4q7OArXsH+LjTf3edxDzJEpUtoQw+Jhn8ChyrX4DhB3yBH/nUv3p5DQR3DEc TZIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778574094; x=1779178894; h=in-reply-to:content-disposition: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; bh=q3CO0P33u84+scWxvorwCoGWLliF7I5j4WDQyYtcSH8=; b=s1Yv6COoouaCKesYhxMGj1wyDnCgMMwchZt4F8dr14wnINA7Blo8dWYixhBrZHbFm0 ZVKvdjkWPV6lE7CUQhcnSAKM1fBaaAhqpcMYoTidbV3ECUP9iX8pq/2rbX9UnK0ulmXq 40wguOfa7Ds0zWw6WzlcVx6/UNhV1D/zYuV3If+PBT4I95QbOPDCmfUZ5n/K/cAO3mf/ UrX5ONGeAW7VCmj95meU+OMqceqpPPM3sJtfxCOHunutBNRaNGTbobxQRdT4lD033grI QItrDCR9k30CXuPawblz3PzpyaE/Jxs6PIZ/vuNE59VK7aQqx6T4BsyP6tjVJjWeaGP+ 8ICg== X-Forwarded-Encrypted: i=1; AFNElJ9wOQ2HWq/78Frt316LMASuT0LocSi+qdUcJsXOTDRoIt0VlQY9n6qck+GQ/pi2unWF9yV277cUF5ZJbQQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyJIQS5P5O8leO4xPzB1/WPzT0FsLgVWfXd8asX3X0+GTKqcUdr DoZopY5gIF6TJGA3j/ZsJoFs2kP8DyVFMUS0YNz8qsIVTp8Dv9wNUsiq X-Gm-Gg: Acq92OEzDx/ev77Si18erAuvI75KsI4fcn6+hKxJkiXMehusjDKD6RQRGtn2SUkMHYU ElWPGD4MbfPy5I5/nGm9JUwnj3PCHe4AQLeVmLpvmi/T9Dg00pDdCiJFRNQIhs1yuvETSnoqzza RVgo4cyVKHRxMIi1hIUfgLolGDLQUCocEQNr7uZ7anYVLYS4wP31RBhtQlqcfhEs+yac7G9VrIh Vo/jr+DsNtoPKuYnh0M9rmZJZ2dPvY3HSUIrE1Z1s86D7Ty/UD5ST9iiPvpV/khmeOtXqIoROcK 9jzNBkmAR3qa4WY0XMt4VMfHc/eSCm+AelUKhitj7i45gmzRypJnPLUGZk31F05I9iS9K6hdcZy R70Yzqh4LJ3Dev0mawD/ULiZmmuI6KKG3SmF1kr8dzv+RzT4J/9c0O/Dr9FNsW9ngondFcp8kpK uU0clmga2/bX0jX2r1UGw= X-Received: by 2002:a05:6000:4210:b0:43b:9a9f:8956 with SMTP id ffacd0b85a97d-4515ce1c80fmr42638728f8f.22.1778574093227; Tue, 12 May 2026 01:21:33 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45491f8d4c3sm30583821f8f.34.2026.05.12.01.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 01:21:31 -0700 (PDT) Date: Tue, 12 May 2026 11:21:28 +0300 From: Dan Carpenter To: Masami Hiramatsu Cc: kernel-janitors@vger.kernel.org, Linux Trace Kernel , linux-kernel@vger.kernel.org, Breno Leitao Subject: Re: [bug report] bootconfig: init: Allow admin to use bootconfig for kernel command line Message-ID: References: <20260512091638.8b95253ab022d7dabf473465@kernel.org> 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: <20260512091638.8b95253ab022d7dabf473465@kernel.org> On Tue, May 12, 2026 at 09:16:38AM +0900, Masami Hiramatsu wrote: > Hi Dan, > > Thanks for reporting. A similar problem is pointed by Sashiko [1]. > > [1] https://sashiko.dev/#/patchset/20260508-bootconfig_using_tools-v1-0-1132219aa773%40debian.org > > On Fri, 8 May 2026 20:07:25 +0300 > Dan Carpenter wrote: > > > Hello Masami Hiramatsu, > > > > Commit 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig > > for kernel command line") from Jan 11, 2020 (linux-next), leads to > > the following Smatch static checker warning: > > > > init/main.c:368 xbc_snprint_cmdline() > > use scnprintf() instead of snprintf() > > > > init/main.c > > 331 static int __init xbc_snprint_cmdline(char *buf, size_t size, > > 332 struct xbc_node *root) > > 333 { > > 334 struct xbc_node *knode, *vnode; > > 335 char *end = buf + size; > > 336 const char *val, *q; > > 337 int ret; > > 338 > > 339 xbc_node_for_each_key_value(root, knode, val) { > > 340 ret = xbc_node_compose_key_after(root, knode, > > 341 xbc_namebuf, XBC_KEYLEN_MAX); > > 342 if (ret < 0) > > 343 return ret; > > 344 > > 345 vnode = xbc_node_get_child(knode); > > 346 if (!vnode) { > > 347 ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf); > > 348 if (ret < 0) > > 349 return ret; > > 350 buf += ret; > > > > In user space snprintf() can return negative, but in the kernel, no. > > It returns the number of bytes (not counting the NUL terminator) which > > would have been copied if there were enough space. So maybe you want > > to do something like: > > > > remain = rest(buf, end); > > ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf); > > if (ret >= remain) > > return -ENOSPC; > > Actually, we need to query the length of required buffer size if buf == NULL > or the buffer size is not enough. > > But as Sashiko pointed, I need to check it with UBSAN. (but I think, > even if @buf is NULL, the @buf is char *, thus it is safe to add some > value...) > Sashiko says that pointer math on a NULL is undefined but we do it all the time in the kernel... When you are a the 800 pound gorilla, you can ask compilers to implement features the way you want them to be. :P regards, dan carpenter