From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 4BB593F7899 for ; Mon, 25 May 2026 17:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779729011; cv=none; b=jMtjZiEwCVCMwgoAA841NauS1Qtw+kQ4dlCp9eA8q8wzujaz/3KK9CtB/BtiuQWnN5NnmsWBlxycnC0cTrVieYFnO1kvhNlq5eSBaOPmWq+6LPhtSfAvnV3gF5Kby+5pDpAGlGvoIpBMnDONEee4m2+W2+SMfoKalISY2NWFf9s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779729011; c=relaxed/simple; bh=PTNg3RyBjtWL4NnI8O0q7hXUoY8uPF4RaVnZMbEInR0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K473DSweVzCAiFdlBfVDXebvFZvizbvnINNoIIbOitJp+qY9GlUx0n96Z2Aq1+/tMTnH63dwJKb80Hk2VrSiDaKIYOk8hJrFQBdM0g7dJwac8uARA72FwYAOldVwbiA7jYeTydpfn75/Y/ytdzlcrVQNyVypQJDECGACF3mFGm4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=GQr1PYm1; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="GQr1PYm1" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490388fd0dbso41525905e9.0 for ; Mon, 25 May 2026 10:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779729007; x=1780333807; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=izugkSqOYsBmSyQ8jfD9m1SVj73YG14U78pRBc6Lai0=; b=GQr1PYm1QRIrfgBC/EILAtR9O17tFRT933ldDJCayUjXIyRMiDnumrFP9i4iPLQuP/ bWYj6u/50hd5AlTl8fnNFXZxscNWQsfvT08lWT2g7USA76CFTeDeB9CAGnGBLt+Jk5Kd lX3x9dDR55Y2wg8pVl8cBGmVyZoFj8APvHLhilXEkRN6z7J5HsqQkRDuiJpcpmZ76bBE nunnNO0efpqrh3Mg+srvekhGI13bTspzjyxHMZeoT7BQvRd6lyijtBc2rfmKjAaENr6C i+8SY1MRgNki/ClY1lWgGG4FXSsH+ZhGYZ0VK7FSfIVhFbKqAWGdmu0VyhcviooSpQ7X 9jYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779729007; x=1780333807; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=izugkSqOYsBmSyQ8jfD9m1SVj73YG14U78pRBc6Lai0=; b=liobomkPFahadXYmDNoFQ4HJHlQOwY08hRxRq0wFtQPoQH5LACQBRrDTilqjBrCm49 OerCx5yIFmCc+ZObEBqRuuKJVqFqKsJpmbEtm363PBhsbJbZR0BEP4QTvfKSwZ2rMX1d 9t6AA1AVPUoABNRNMvNPujjuxsQlYHjewfknbnwuQsrpIyXWqOihj2UHonz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17b1804b1-49044ebc257mr277307095e9.31.1779729006482; Mon, 25 May 2026 10:10:06 -0700 (PDT) Received: from ?IPV6:2a00:1028:838d:271e:8e3b:4aff:fe4c:a100? (dynamic-2a00-1028-838d-271e-8e3b-4aff-fe4c-a100.ipv6.o2.cz. [2a00:1028:838d:271e:8e3b:4aff:fe4c:a100]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4904526c926sm456877405e9.1.2026.05.25.10.10.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 10:10:06 -0700 (PDT) Message-ID: Date: Mon, 25 May 2026 19:10:03 +0200 Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 08/11] params: Convert generic kernel_param_ops .get helpers to seq_buf To: Kees Cook Cc: Luis Chamberlain , Pengpeng Hou , Richard Weinberger , Anton Ivanov , Johannes Berg , "Rafael J. Wysocki" , Len Brown , Corey Minyard , Gabriel Somlo , "Michael S. Tsirkin" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Bjorn Helgaas , Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Greg Kroah-Hartman , Jiri Slaby , Alan Stern , Jason Wang , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Jason Baron , Jim Cromie , Tiwei Bie , Benjamin Berg , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , "Maciej W. Rozycki" , Srinivas Pandruvada , Peter Zijlstra , Heiko Carstens , Vasily Gorbik , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vinod Koul , Frank Li , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Andy Shevchenko , Georgia Garcia , kvm@vger.kernel.org, dmaengine@vger.kernel.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, linux-acpi@vger.kernel.org, openipmi-developer@lists.sourceforge.net, qemu-devel@nongnu.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20260521133315.work.845-kees@kernel.org> <20260521133326.2465264-8-kees@kernel.org> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260521133326.2465264-8-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 5/21/26 3:33 PM, Kees Cook wrote: > Convert the generic struct kernel_param_ops .get helpers in > kernel/params.c directly to the seq_buf signature, drop their legacy > "char *" form, and refresh prototypes in : > > param_get_byte/short/ushort/int/uint/long/ulong/ullong/hexint > param_get_charp/bool/invbool/string > param_array_get > > The STANDARD_PARAM_DEF() macro expands to a seq_buf body for every > numeric helper. param_array_get() now writes element output directly > into the parent seq_buf when the element ops provide .get; it only > allocates the per-call PAGE_SIZE bounce buffer when the element ops > still use the legacy .get_str path. The common "rewrite the prior > element's trailing newline as a comma" step lives outside both > branches so the two paths share it. > > The non-core changes in this commit (arch/x86/kvm, mm/kfence, > drivers/dma/dmatest, security/apparmor) are the small set of callers that > directly invoke one of the converted generic helpers from their own .get > callback (e.g. an apparmor wrapper that adds a capability check and then > delegates to param_get_bool()). Because the helpers' signature changes > here, these wrappers must move in lockstep. Each of them is updated > to take "struct seq_buf *" and pass it through; param_get_debug() in > apparmor also pulls aa_print_debug_params() (and its val_mask_to_str() > helper, in security/apparmor/lib.c) over to seq_buf, since that is the > only consumer. No other behavioural change is intended. > > Custom .get callbacks that do not delegate to a generic helper (and > therefore still match the .get_str signature) are routed automatically > to the .get_str field by the DEFINE_KERNEL_PARAM_OPS _Generic dispatcher > and are deliberately left alone here, to be changed separately within > their respective subsystems. > > Signed-off-by: Kees Cook > --- > [...] > @@ -453,36 +457,46 @@ static int param_array_set(const char *val, const struct kernel_param *kp) > arr->num ?: &temp_num); > } > > -static int param_array_get(char *buffer, const struct kernel_param *kp) > +static int param_array_get(struct seq_buf *s, const struct kernel_param *kp) > { > - int i, off, ret; > - char *elem_buf; > const struct kparam_array *arr = kp->arr; > struct kernel_param p = *kp; > + char *elem_buf = NULL; > + int i, ret = 0; > > - elem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > - if (!elem_buf) > - return -ENOMEM; > + for (i = 0; i < (arr->num ? *arr->num : arr->max); i++) { > + size_t before = s->len; > > - for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) { > p.arg = arr->elem + arr->elemsize * i; > check_kparam_locked(p.mod); > - ret = arr->ops->get_str(elem_buf, &p); > - if (ret < 0) > - goto out; > - ret = min(ret, (int)(PAGE_SIZE - 1 - off)); > - if (!ret) > + > + if (arr->ops->get) { > + ret = arr->ops->get(s, &p); > + if (ret < 0) > + goto out; > + } else { > + if (!elem_buf) { > + elem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); > + if (!elem_buf) { > + ret = -ENOMEM; > + goto out; > + } > + } > + ret = arr->ops->get_str(elem_buf, &p); > + if (ret < 0) > + goto out; > + seq_buf_putmem(s, elem_buf, ret); > + } > + > + /* Nothing got written (e.g. overflow) — stop. */ > + if (s->len == before) > break; > + > /* Replace the previous element's trailing newline with a comma. */ > - if (i) > - buffer[off - 1] = ','; > - memcpy(buffer + off, elem_buf, ret); > - off += ret; > - if (off == PAGE_SIZE - 1) > - break; > + if (i && s->buffer[before - 1] == '\n') > + s->buffer[before - 1] = ','; > } > - buffer[off] = '\0'; > - ret = off; > + ret = 0; > out: > kfree(elem_buf); > return ret; Since you're almost completely rewriting the logic in param_array_get(), I suggest tightening it up a bit. The function could warn or return an error when a kernel_param_ops::get/get_str() call adds a string that doesn't terminate with '\n', specifically, when the call adds either a zero-length string or a non-zero-length string that ends with a different character (unless an overflow occurred). The updated code silently stops the loop when a get call returns a zero-length string. Similarly, handling of a string not terminated by '\n' is halfway there because of the added check "s->buffer[before - 1] == '\n'". -- Thanks, Petr