From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1DE8C7618B for ; Tue, 23 Jul 2019 15:39:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B23B1217D4 for ; Tue, 23 Jul 2019 15:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388708AbfGWPjz (ORCPT ); Tue, 23 Jul 2019 11:39:55 -0400 Received: from smtprelay0127.hostedemail.com ([216.40.44.127]:41191 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725601AbfGWPjy (ORCPT ); Tue, 23 Jul 2019 11:39:54 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay08.hostedemail.com (Postfix) with ESMTP id DB889182CF665; Tue, 23 Jul 2019 15:39:52 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: fowl35_38e5e5eee520d X-Filterd-Recvd-Size: 2880 Received: from XPS-9350.home (cpe-23-242-196-136.socal.res.rr.com [23.242.196.136]) (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA; Tue, 23 Jul 2019 15:39:50 +0000 (UTC) Message-ID: Subject: Re: [PATCH V2 1/2] string: Add stracpy and stracpy_pad mechanisms From: Joe Perches To: Rasmus Villemoes , Linus Torvalds , linux-kernel@vger.kernel.org Cc: Jonathan Corbet , Stephen Kitt , Kees Cook , Nitin Gote , jannh@google.com, kernel-hardening@lists.openwall.com, Andrew Morton Date: Tue, 23 Jul 2019 08:39:49 -0700 In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.5-0ubuntu0.18.10.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-07-23 at 16:37 +0200, Rasmus Villemoes wrote: > On 23/07/2019 15.51, Joe Perches wrote: > > Several uses of strlcpy and strscpy have had defects because the > > last argument of each function is misused or typoed. > > > > Add macro mechanisms to avoid this defect. > > > > stracpy (copy a string to a string array) must have a string > > array as the first argument (dest) and uses sizeof(dest) as the > > count of bytes to copy. > > > > These mechanisms verify that the dest argument is an array of > > char or other compatible types like u8 or s8 or equivalent. > Sorry, but "compatible types" has a very specific meaning in C, so > please don't use that word. I think you are being overly pedantic here but what wording do you actually suggest? > And yes, the kernel disables -Wpointer-sign, > so passing an u8* or s8* when strscpy() expects a char* is silently > accepted, but does such code exist? u8 definitely, s8 I'm not sure. I don't find via grep a use of s8 foo[] = "bar"; or "signed char foo[] = "bar"; I don't think it bad to allow it. > > V2: Use __same_type testing char[], signed char[], and unsigned char[] > > Rename to, from, and size, dest, src and count > > count is just as bad as size in terms of "the expression src might > contain that identifier". But there's actually no reason to even declare > a local variable, just use ARRAY_SIZE() directly as the third argument > to strscpy(). I don't care about that myself. It's a macro local identifier and shadowing in a macro is common. I'm not a big fan of useless underscores. I think either works.