From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 63DE03A5427 for ; Mon, 11 May 2026 20:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778531701; cv=none; b=YXYiuUshEOuEp9Kzf2wDMBSh1/I+5pNEQnXUz4p26SBg5gFmpK1euQRmpjgdLlaFLOKuIxBKDnrkglETBd74dXFFX8bdFy+QnPzPCaZYPN2c55YsLBWm3i8qD7M0YYrcGEMFp+Gb5rroA+gXp4p5uOULlIBWNv9vNf/MbBc7Wr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778531701; c=relaxed/simple; bh=tYRtTOy1sHxq4Rk5XvcIzIiOnuPKAFIZOrQMkYea6rw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e4zI5vduPQLH1FOzLHDwysavAASVbnzv+zghfLtV5Wr9juznVgy5rXK6xxTyFldNawW/cgtY5NStW0B8SjztnpizT5kJXpzB6nijdFjaCrYqMEiI46NzMvXiTGWwbUS5Fif4/ce+Q/TLW7JS2S41RNnCvN7/kfWqcA2PpiIImbE= 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=tLcK/Or6; arc=none smtp.client-ip=209.85.128.47 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="tLcK/Or6" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48d102471a4so47367635e9.2 for ; Mon, 11 May 2026 13:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778531698; x=1779136498; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=T5xopMfEr6HUMHZClhAXHEE+h7URb7mb9soskalU1hg=; b=tLcK/Or6NZzRstHbLTu2se61PyVivEyWF9oYzxtyiDW9myOMgQ6YdfFN/3vNCFYCbb DW24naCKzLabB/Ng6jCZmSZ7Wb5DA1f532esE6hZr2wV6jmdLXw7VE3ARyR6cZYzeTR8 hQSkr+m+hZ1V41OLQKRzBw3kpKdVxNiI7BzC7atUKswSEbWbd3cNhAXocmofsKw4gNtR zeW6MBGJIPvuyaW+gCaSEMpEQ8vny2MOfY+pL7rUYDLoYSeu7tN9XqaGiusyjN/+sumU R0IhdrMgju8QezpnwZzxkXodoHyqr291O1PriMemqMrJ1gHFwAcPE1IRYOANAh2455iY zCHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778531698; x=1779136498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=T5xopMfEr6HUMHZClhAXHEE+h7URb7mb9soskalU1hg=; b=oOKeLyUiv0kes+gtKcdZRhvncyKBwvLgNCPUWgVwC1+oG0mYKXpYYUViG1aE8KZE+u 5S3124EAMecg5zpLqo76mX26umeU5Bb9x83GzYdO3ovdel44oK77AJatSR/0VhOfIopk ttw3cH3P1YYD4gVvAc1IW2+nVe8DL3/6zkdyj1vrCwGgCtZ+tIV/Phq3fBIdy/4xcjQ4 25DqH9M+OVxSK+7Mg97n2OWm8gsnWJgBpsY+EmWAJ+uvpd33B95t3Q6tROjNdVn5JCKD lRkH1pedKaZv17bYx1O+s+MiFIqVM5X+/E+DD32iyjPmvI9UK3oloSb6G+BGJ4Vqt7l9 YDtw== X-Forwarded-Encrypted: i=1; AFNElJ9FMlRMuluRWJU825OO4mKi5Q/1HJnHWzkqnWwI5NwwypG1DY7YOv8XG7hsJh2aUzLL/sIW+Ec1HL+6tsk=@vger.kernel.org X-Gm-Message-State: AOJu0YyI0sFxtnqjoovye25B4loe9L1ngUfoCxC0OftXtzJfP3g8lPEq Max2zSIGVLrqnpSXkOx53jr8sHDCXHs6YKbZ9cA9D9PmRZs7PjLK/FTe X-Gm-Gg: Acq92OEC6aUkH2gJ37ax0qBAxZ8OdH8UPFgG+mpm2CA2kCJWbwy9KkFpkQPlHDjcUMV jF2zXfmBo0FPD5TkGRSONEzItksWFjAzMkOr9PQqaok7yfG6riyZ+EkiXpfa7BqMGqjV+Hf9BwN YyAca2P/bsqM54DqAu5OryOdeEnwzDB5YMT+CEXTR6udVWwRHRK9SIPJM9+bB3UG/05jrphTIm7 +C0xH6/U00NHxg8tQps1xSxgtrK2GN8EedDGU2oDBsixhTRk6coL3D/WFPWMUNNp9Iu2Vm3s4dl lEaiJT2PyRpyT8g2iXpnUi4DsehP52jqVTEaN5zB+QKukh0kbqxDKTVuUBKnoxXn9VllqMwMSkr O+8aaulgQ8z2YbCLG869yyJXervkNnjCT7KoEJDsSeb7ovfmL6Uj3213K3g3RMLdoex/EQNn+pJ nTCstbJ9M6AVAZ7MsmBZ4vZ9QhWsiQeRJxkV+SRPAGWz/qm5CI7LHPue3dQbOw X-Received: by 2002:a05:600c:8594:b0:48a:52ce:a4b1 with SMTP id 5b1f17b1804b1-48e676a4e1fmr185836335e9.15.1778531697513; Mon, 11 May 2026 13:34:57 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8e62944bsm3582235e9.8.2026.05.11.13.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 13:34:56 -0700 (PDT) Date: Mon, 11 May 2026 21:34:54 +0100 From: David Laight To: Kees Cook Cc: Geert Uytterhoeven , Manuel Ebner , andy.shevchenko@gmail.com, apw@canonical.com, corbet@lwn.net, dwaipayanray1@gmail.com, joe@perches.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, lukas.bulwahn@gmail.com, skhan@linuxfoundation.org, workflows@vger.kernel.org Subject: Re: [PATCH 1/2] [PATCH 1/2] Doc: deprecated.rst: add strlcat() Message-ID: <20260511213454.22f00bff@pumpkin> In-Reply-To: <202605111206.ECA86141@keescook> References: <20260510164907.57176-2-manuelebner@mailbox.org> <20260510165159.57457-2-manuelebner@mailbox.org> <20260511142649.463c3ea5@pumpkin> <202605111206.ECA86141@keescook> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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 Mon, 11 May 2026 12:07:38 -0700 Kees Cook wrote: > On Mon, May 11, 2026 at 02:26:49PM +0100, David Laight wrote: > > On Mon, 11 May 2026 13:40:55 +0200 > > Geert Uytterhoeven wrote: > > > > > Hi Manuel, > > > > > > On Sun, 10 May 2026 at 18:52, Manuel Ebner wrote: > > > > add strlcat and alternatives > > > > > > Thanks for your patch! > > > > > > > --- a/Documentation/process/deprecated.rst > > > > +++ b/Documentation/process/deprecated.rst > > > > @@ -162,6 +162,12 @@ if a source string is not NUL-terminated. The safe replacement is strscpy(), > > > > though care must be given to any cases where the return value of strlcpy() > > > > is used, since strscpy() will return negative errno values when it truncates. > > > > > > > > +strlcat() > > > > +--------- > > > > +strlcat() must re-scan the destination string from the beginning on each > > > > +call (O(n^2) behavior). Alternatives are seq_buf_puts(), seq_buf_printf(), > > > > +snprintf() and scnprintf() > > > > > > The last two not only require the caller to keep track of the offset > > > in the buffer, but also using "%s" when storing passed strings. > > > > Which also means they are significantly slower. > > Mind you, some code has: > > strlcat(buf, "\n", SIZE); > > return strlen(buf); > > which carefully scans the string twice. > > Since the '\0' isn't always needed (eg 'show' functions), this can be: > > len = strlen(buf); > > buf[len] ='\n'; > > return len + 1; > > Of course, the code could often easily get the length by other means. > > I think I'd prefer to only recommend using seq_buf API. Or for sysfs, > sysfs_emit() as seq_buf hasn't been extended there yet. True for the docs, but rather more work when you are just trying to get rid of strcpy() and strcat() calls. It can be hard working out whether you can use sysfs_emit() or not. (And I recently failed to find where the PAGE_SIZE buffer is actually allocated; I'm sure it should just be 4k.) -- David > > -Kees >