Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1524327rdb; Sat, 10 Feb 2024 05:51:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIYkkeaFqPAuXCA3E1wUM3LfGOKQgr2MlKWSStSTqRgLfk0Q2yVRfPFK8JT812UqdX2v5O X-Received: by 2002:ad4:5d6b:0:b0:68c:6ef2:4736 with SMTP id fn11-20020ad45d6b000000b0068c6ef24736mr2943195qvb.3.1707573115623; Sat, 10 Feb 2024 05:51:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707573115; cv=pass; d=google.com; s=arc-20160816; b=fwPSAO3Mfng5lwvPHXvUUraMJ5lgrplayffMq1gzmswbVEdsTHW3UkBPaDeNj2b2yF pL7U9yYfngLJ6HoGH5nz7/FquPfdXQGxQaVTvVL4Q6rt00fq8tWyLtvNth7VzLXhSJAH Os1rgOPn4QO4JR3RoGG7lpj51hA0L2Uyphj2qxG0LDvkv3bzq1mCMMhL4t7xEk/ex94/ JliWAplM+hFYBfv2gA0qK0pPuHo8r2VUtsXsW/U2UJjBLFykFWQdeg4d8wVjwKoa2MR2 0FFfhX3aBBiPGZrO5eEwa7WdK8uDB7A3g1FYudYvfVu3qTrqf2ywVtXVOJFa9v8hQIsz iTxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=rq0QhLnHn45nG0JxQ5l0E20sBmdfRxrFjSt1qcOwM4g=; fh=kPSnE+JgG7P4UmDOp8CGmuDHDMnYgUrx1AHfJBHwH4o=; b=OhDssRW32kG9g79cQosiEVLZUnrznECnKauOc3GkmLLKlq1CU0FP4dYUuxBjDUnFLS d/w29Ra1+SZA/azG9olZwusR5v3rXHyxJuh/dO9bEvL4cCJIIeTJ+N98SY7eo+N/IEmB PLibke/1xtE3be0W5YOr35rudlTu4b450MHdIg0+vrFDdcRS+l/l56MseFpo0xu8cKqd QFdu0Wktf4fhBNysuy8480UI+3qEvkZP7OU/hu3+cPHB5wUn13vnL0OdBAYPfpvfjS89 VbGPQebksGuZyDw0KXRNPzTzdM/4SGuDDAj6QXa/FUB3y0p+D71nKryvrBiUfUPoLJtZ dxrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-60412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com X-Forwarded-Encrypted: i=2; AJvYcCXT6sVBjiTbMAZPQrKOsqfVycd/lNLISBcWzBNQQIrkZzs77V77uI+i9wiosgkbF5B/SmPkhX9vwbZLGNsfPSDSrPqqSTj/3QH7Nr35xA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 3-20020a05621420a300b0068c64c00962si4208866qvd.532.2024.02.10.05.51.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 05:51:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-60412-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6106E1C213E3 for ; Sat, 10 Feb 2024 13:51:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60B1D53815; Sat, 10 Feb 2024 13:51:49 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (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 B3CD02114 for ; Sat, 10 Feb 2024 13:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707573108; cv=none; b=d5NgmClolLxoIK97HCoAN2WURTuKzcL6ZkgPGsikvRhcuEWyqIjzF7LWuzeHJnRi6h48nvA9j3EejmqHtYAMYO+bBCYAObdSfMFA9gU+MQaUp7NyVaqqB+2MDaLTzdVhy+l1RmAmrFNDutRxv2XJAkzKDgYoRPviolA7YoKv5Gg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707573108; c=relaxed/simple; bh=mJNh+djTCqqKsg3FJVqIIWwHEHq7WgIc5UhFkuEM2bw=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=EhDbk2vjkm23LxXdfEM5ljpsxxOgfnLsjVpw7bSr0LkJ5AqVoudN6vNS2U1iS5zj+lQod0TtswjIku5eo+DN1wix+0MvmL9yl9YALRvw1BFeSkkFoUjwfNclAc9noKHJdmkBE5teql6YidqPdYBYMMHu28xdpHnFtyX/YEY7lz0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-75-PUFwWm4HMsG8Z9qT-lEh4g-1; Sat, 10 Feb 2024 13:51:40 +0000 X-MC-Unique: PUFwWm4HMsG8Z9qT-lEh4g-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 10 Feb 2024 13:51:18 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sat, 10 Feb 2024 13:51:18 +0000 From: David Laight To: 'Pavel Machek' , Justin Stitt CC: Kees Cook , Andy Shevchenko , Rasmus Villemoes , "linux-hardening@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [RFC] string: Allow 2-argument strscpy() Thread-Topic: [RFC] string: Allow 2-argument strscpy() Thread-Index: AQHaWe5TIJbv1x38yUWctvLGNyIGYrEDmx4Q Date: Sat, 10 Feb 2024 13:51:18 +0000 Message-ID: <4b396628800149c69e157f0340778fbf@AcuMS.aculab.com> References: <20240129202901.work.282-kees@kernel.org> <20240129215525.4uxchtrywzzsrauc@google.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Pavel Machek > Sent: 07 February 2024 17:52 > > > Using sizeof(dst) is the overwhelmingly common case for strscpy(). > > > Instead of requiring this everywhere, allow a 2-argument version to b= e > > > used that will use the sizeof() internally. > > > > Yeah, this is definitely the case. I have a ton of patches replacing > > strncpy with strscpy [1] and many of them match the pattern of: > > | strscpy(dest, src, sizeof(dest)) > > > > BTW, this hack for function overloading is insane. Never really looked = into > > it before. >=20 > This hack is insane, but this is also highly confusing, please don't > do this. A much simpler 'hack' - here defaulting in 16. Although you'd probably want a compile-time check on the number of arguments. And convert 'sizeof 'non-array' to (say) -1 and error a length that is a constant -1. =09David extern int func_2(void *, const void *, int); #define func_1(_p0, _p1, len, ...) func_2(_p0, _p1, len) #define func(_p0, ...) func_1(_p0, __VA_ARGS__, 16) int f1(void *p0, const void *p1) { return func(p0, p1); } int f2(void *p0, const void *p1, int len) { return func(p0, p1, len); } - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)