Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7634021ybi; Mon, 22 Jul 2019 17:22:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqgdJsBUEFcWEVWdbQILowOGvDuhU7//bU3df55+3D63v3gEG6t6WFYYdrQghVS5LMU/+7 X-Received: by 2002:a17:902:20b:: with SMTP id 11mr78778798plc.78.1563841340291; Mon, 22 Jul 2019 17:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563841340; cv=none; d=google.com; s=arc-20160816; b=RciEscjZ5uhNcqYE2B3maRLQ28jRWVIQPUaLHLJKpCrdlOPKSEOkCzn7bDAjTpUCE2 a3EfOyL7YIvQF3IeBO3Ay7GeMr04Inz2PZwQGnmZYevR/ycaGZn+sEGRxEHt98WpRzOY SMAmcQvQ54VXEkg6xTwqN1W7NTq8Sua5JAHnMLNL7V1E0g/lbbc0/1aGSQwYrYKhHE+j WbiqzCUeVI9F5WQbIGMTMWmBqUZroY8sMxSlJtfB2sYPAr9uOEIsSU7Di6XcV5bXcQ6E WImV2ssX7iYEjcbyJQWd+1jqRlN+COXyA+4zb7YXX1+IhB4qfkb7FtUAALTVcBquWmn5 pHMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tGQ3tU84YUPv9anAGKOasBEXJrM8FRAxn66lIhfR02Q=; b=fLGtOoMzAZFtKBblVTjq5oXVGMEvAL2yWWhD2AQ9cxo6k42KCSot2jNH9PQ5IGouBT 5lZBq6Tiw3AdQhQX8MkDRimqIQ88ZeiQ1i+zGffSwB41r9hJ2JnogUb3K42AVTJ3hn6J zrwzxWXzRKtjwSGQbkRADODajcbksPo8BstBjJt0o1OGgiYGcKB8QCxOSTgEZc8ipG/M Mh/3eKoHQfa9W2g945qkePwmRgmZe4W3uiM/wVC72H0JFxmQ5O4Gw+IZVbz2JfSLyZUw P3Zx5KsMqY4N42HEeDrheIrBObhgdORBEtEKMySdTJDZaq5JVJO6hEAlm3iaeyKduL6O LcJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DrTCv0T3; 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 z193si10098230pgd.235.2019.07.22.17.22.02; Mon, 22 Jul 2019 17:22:20 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DrTCv0T3; 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 S1728240AbfGVS1M (ORCPT + 99 others); Mon, 22 Jul 2019 14:27:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58778 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbfGVS1L (ORCPT ); Mon, 22 Jul 2019 14:27:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tGQ3tU84YUPv9anAGKOasBEXJrM8FRAxn66lIhfR02Q=; b=DrTCv0T34g/AEpsLdSUB+OweT BU7fu+Dm0wrSTGO41re0jxJH+t+vM9hye9RL1wAr88bj0oPWG70t2JBWoOI48HrxEMlVPACbeN1uu /ch/Hmv1HcofsIRa5N2G5LiDoyS7rybkBUntp6Vndt3qIKhBnQTqQWRwkkXEP16OLtG6iVXbr4Ee6 /dIFiZlM864pj2EDvEf/bCQtAHA6Sm4ltZVMH4ZT8suuvxhHl7Eyy0p7VoDwYOioVWqQhYZyUlQyn eVCYgn6N9nZvdHT5OXq2lpHXkTaQNKAVrPqr3EDFcnwZjOk+8HtfltejH6pNYK8GHwVU9i9a/fxB2 5eGUReVYA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1hpd1c-0001KV-88; Mon, 22 Jul 2019 18:27:05 +0000 Date: Mon, 22 Jul 2019 11:27:04 -0700 From: Matthew Wilcox To: Joe Perches Cc: Kees Cook , Nitin Gote , akpm@linux-foundation.org, corbet@lwn.net, apw@canonical.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Rasmus Villemoes Subject: Re: [RFC PATCH] string.h: Add stracpy/stracpy_pad (was: Re: [PATCH] checkpatch: Added warnings in favor of strscpy().) Message-ID: <20190722182703.GE363@bombadil.infradead.org> References: <1562219683-15474-1-git-send-email-nitin.r.gote@intel.com> <201907221031.8B87A9DE@keescook> <2c959c56c23d0052e5c35ecfa2f6051b17fb2798.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c959c56c23d0052e5c35ecfa2f6051b17fb2798.camel@perches.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 10:58:15AM -0700, Joe Perches wrote: > On Mon, 2019-07-22 at 10:43 -0700, Joe Perches wrote: > > On Mon, 2019-07-22 at 10:33 -0700, Kees Cook wrote: > > > On Thu, Jul 04, 2019 at 05:15:57PM -0700, Joe Perches wrote: > > > > On Thu, 2019-07-04 at 13:46 -0700, Joe Perches wrote: > > > > > On Thu, 2019-07-04 at 11:24 +0530, Nitin Gote wrote: > > > > > > Added warnings in checkpatch.pl script to : > > > > > > > > > > > > 1. Deprecate strcpy() in favor of strscpy(). > > > > > > 2. Deprecate strlcpy() in favor of strscpy(). > > > > > > 3. Deprecate strncpy() in favor of strscpy() or strscpy_pad(). > > > > > > > > > > > > Updated strncpy() section in Documentation/process/deprecated.rst > > > > > > to cover strscpy_pad() case. > > > > > > > > [] > > > > > > > > I sent a patch series for some strscpy/strlcpy misuses. > > > > > > > > How about adding a macro helper to avoid the misuses like: > > > > --- > > > > include/linux/string.h | 16 ++++++++++++++++ > > > > 1 file changed, 16 insertions(+) > > > > > > > > diff --git a/include/linux/string.h b/include/linux/string.h > > > > index 4deb11f7976b..ef01bd6f19df 100644 > > > > --- a/include/linux/string.h > > > > +++ b/include/linux/string.h > > > > @@ -35,6 +35,22 @@ ssize_t strscpy(char *, const char *, size_t); > > > > /* Wraps calls to strscpy()/memset(), no arch specific code required */ > > > > ssize_t strscpy_pad(char *dest, const char *src, size_t count); > > > > > > > > +#define stracpy(to, from) \ > > > > +({ \ > > > > + size_t size = ARRAY_SIZE(to); \ > > > > + BUILD_BUG_ON(!__same_type(typeof(*to), char)); \ > > > > + \ > > > > + strscpy(to, from, size); \ > > > > +}) Where does the 'a' in 'stracpy' come from? Googling around finds other people using a function called stracpy, but it takes different arguments. http://stracpy.blogspot.com/ takes a size argument, as does https://docs.polserver.com/doxygen/html/d5/dce/stracpy_8cpp_source.html The one in the 'Links' webbrowser (can't find a link to its source) seems like a strdup clone.