Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9469906ybi; Wed, 24 Jul 2019 04:42:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUnJADi8x7MQX7dlWcOP+9BA7/S3V7STo9GmNcQGQPRZIzoHVI5o5JO6rQ7QVLQJQytNTK X-Received: by 2002:a62:874d:: with SMTP id i74mr10677392pfe.94.1563968578500; Wed, 24 Jul 2019 04:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563968578; cv=none; d=google.com; s=arc-20160816; b=sQMSpVlVrrO3Uk+2QaSJm8DsSjFjWQVtayeRY5bv81jokado/UzvPJ3KfQ6VFPW2xX TR2+2I77Lo2v9LnEIcevUOePz6ELD/Y5ppa85jKaY2qdWVF29CtM8Ex8itIU2+T//BMi +O5KDrtAeLR+ybOz18kj2w3Id8WqMKwiUf40CA7KPG/YRVedg0853sGfwJ+qqGMXlDEJ mFOB/NH88mxeTnOn+oktNFsg6nRUvyRnzOn/XCe8/oYuuujMAamaKVyZ0ZLzAQggAw27 jbymHXwADHIOTZesdWgSmFFDbTD+ZHTcOJXAXpZdxaHGpRlFFtmbv/uhRF1Z8Dsm6ADI vr6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=MlQvzzAdCfiZrjQKd6ZnxvVO6XlEjAEftd+Km80mFSA=; b=tZ3K3wh194p2aSg3NvwmFnq0fgoCjJijMuCwACQjMg0cJFSPIgLq+S2eDE9vLBlbE0 8CBgkVKeTZOBVHgbuzGFlSuzCq7M767BGQhH2tR1fQNpLc7JAl8J74y2IzXPa4gkllih oSnP8BaLHpRH3PF9VVAU4J1jqVYuw0qcLD5GiecpfQz5E1AyocpxsBLmH0S1HAMe3DmF Dj9BjoGISbTun9BKjksmOCmCjsmh9KelKQdoOH+apQrs+sRy3NhcWLMcaj52oHiWthdY 1yA2drgpft8u4YsU2Ewy5H7pEArqVPnRxSE/txlp3OR0kXlhpFMixESNe26Q5hlN1JlO iuyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g18si5197292plq.190.2019.07.24.04.42.43; Wed, 24 Jul 2019 04:42:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727544AbfGXLkf (ORCPT + 99 others); Wed, 24 Jul 2019 07:40:35 -0400 Received: from smtprelay0172.hostedemail.com ([216.40.44.172]:55115 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727378AbfGXLkf (ORCPT ); Wed, 24 Jul 2019 07:40:35 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 0582A83777ED; Wed, 24 Jul 2019 11:40:34 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2828:2915:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3871:3872:3874:4321:4362:5007:8603:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12297:12740:12760:12895:13069:13311:13357:13439:14181:14659:14721:21080:21627:30054:30069:30079:30090:30091,0,RBL:23.242.196.136:@perches.com:.lbl8.mailshell.net-62.8.0.180 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:29,LUA_SUMMARY:none X-HE-Tag: shape98_3ee351f3c5a54 X-Filterd-Recvd-Size: 2144 Received: from XPS-9350.home (cpe-23-242-196-136.socal.res.rr.com [23.242.196.136]) (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA; Wed, 24 Jul 2019 11:40:32 +0000 (UTC) Message-ID: Subject: Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms From: Joe Perches To: Kees Cook Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Jonathan Corbet , Stephen Kitt , Nitin Gote , jannh@google.com, kernel-hardening@lists.openwall.com, Rasmus Villemoes , Andrew Morton Date: Wed, 24 Jul 2019 04:40:30 -0700 In-Reply-To: <201907231435.FABB1CC@keescook> References: <7ab8957eaf9b0931a59eff6e2bd8c5169f2f6c41.1563841972.git.joe@perches.com> <201907231435.FABB1CC@keescook> 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 14:36 -0700, Kees Cook wrote: > On Mon, Jul 22, 2019 at 05:38:15PM -0700, 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 (to) and uses sizeof(to) as the > > size. > > > > These mechanisms verify that the to argument is an array of > > char or other compatible types like u8 or unsigned char. > > > > A BUILD_BUG is emitted when the type of to is not compatible. > > > > Signed-off-by: Joe Perches > > I think Rasmus's suggestion would make sense: > > BUILD_BUG_ON(!__same_type(typeof(to), char[])) I think Rasmus had an excellent suggestion. I liked it and submitted it as V2. > Reviewed-by: Kees Cook Thanks.