Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759026AbbGHUVS (ORCPT ); Wed, 8 Jul 2015 16:21:18 -0400 Received: from mail-db3on0081.outbound.protection.outlook.com ([157.55.234.81]:14667 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755378AbbGHUVG (ORCPT ); Wed, 8 Jul 2015 16:21:06 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; vger.kernel.org; dkim=none (message not signed) header.d=none; From: Chris Metcalf To: Linus Torvalds CC: Chris Metcalf , Al Viro , Fabian Frederick , Randy Dunlap , Rickard Strandqvist , , Peter Zijlstra , "David S. Miller" , Frederic Weisbecker , Andrew Morton , Sam Ravnborg , Stephen Rothwell , "Theodore Ts'o" , Grant Likely , Dan Carpenter , Geert Uytterhoeven , Michael Ellerman , Linux Kernel Mailing List , Subject: [PATCH v2 0/3] add new strscpy() API for string copy Date: Wed, 8 Jul 2015 16:20:42 -0400 Message-ID: <1436386845-11989-1-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 References: <1430409677-13284-1-git-send-email-cmetcalf@ezchip.com> In-Reply-To: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD019;1:k4bt6pzaJnp5U1BQDqVoaJqTSCwKfQJDk6Ky1y9LHEA8gK1RKN+0tEl2sVC8DHjkoJrBoQVu4/hSKSxrmM8gla1KDfGgiPevoVWgZmpj6U2tbaPnFFZJ9QUZoW0HUeN4dXpfgI4uCicF/N78hHfkuhQWdPkXTM+Co/hM/6+DndS7qRbPSrhh4648/2MxBAvPKMJgmNAVumdKFb6+y9k6pqfBAvBr9s15b6IXzKxeDC5ZDf5bkU28qKDwMydpS/1kdJD1/bKdW/9vmtaV11OYd2uctaeO3+rYdsc9mgEHXjKHpc1vFURNxd7i0nX/EkLAtTRyddUFHSmZDvXoho8AT2aSYwYTbraz1Vwg11bGazCcQhTbKeSzyyqIou/lPs4ahh5NtfDEs8bzHUdVF78Vo+UzAb1LdxmOXXseI3tuRVldjcelH9ksw0wNqOG5Kd7Y X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(339900001)(189002)(199003)(77156002)(105606002)(36756003)(86362001)(50466002)(106466001)(62966003)(6806004)(50226001)(110136002)(42186005)(5001960100002)(104016003)(229853001)(19580395003)(87936001)(50986999)(189998001)(5003940100001)(46102003)(47776003)(85426001)(33646002)(48376002)(15975445007)(2950100001)(76176999)(92566002)(21314002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR02MB0776;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;DB5PR02MB0776;2:PXVgyBpKdIbteS6e/RpgdsobK1Dz3O5t2a0bPdLyv31ZS/BenHWiLN/6EeLyhVx4;3:Llz9BjfoGAnKgwQtlgBKZlAOYh3vpSltlokrhIjHdmuEDxVVMJHXTvy2xWwW9SVkD3rt9crFjoZYQoH9nCZRgFFZny6y5E/hkA1sOnCeu+mzClHOrhNamRPhm8kIoxGPjQQruwKdP+cEBbeQOO8k+b5lxsYLJp0GhEDQwNl7A/WdP1gGHTScIA0swApwt4jtOBK6hscwfwWiQJLvt3Oql9bLIXkm4snZIVhmaAX59VWcBgbA8gs+TiDAptVlj3Q7;25:ZL5VvzNpodvQsgeA0Z0w0O4gxc5zlf5IHOec4WMpQXWzJfWuh0vVkUhGzplcImyGJUcd0IS5oNxq/3VPiIKDmyaOEyzzfcO11OCwusuI0pvJvXjws80vGHrFHUTBTZd4cdVrPkb0arS/lVvUMxQrvSUBFh+93bBptcghxL60UDHT7NR+Vgf0jZdzv+wPp9QQNRTlrefrjLbg1xHESQ6IiNKtC/zeJZ8zL5hqxqULqVHITWAy1PO4Wo9SSdigY2OK/lAPl+La56Blkue6AJl6sw==;20:NMjxG2IK4jhuXk481CKTmyVMNV+ajbgyZsx4nL/xaF6uQisH9pA8/7jHMHI9wk3WNujR7bJkkTEo202UGrSHTD4up3GkQqKXwz3rJstXDVsS7DKYkGKRQGoUwLqbg58F5LMQy67J/tkSORA2Sg3RVNim3S7Yrp8ZVyKIzB0AwlI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR02MB0776; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:DB5PR02MB0776;BCL:0;PCL:0;RULEID:;SRVR:DB5PR02MB0776; X-Microsoft-Exchange-Diagnostics: 1;DB5PR02MB0776;4:3veNIH9ZqNCdrdm17BuadDBVZsRVWontNW1Wk/N0bNoRrGGErLW11ygeafDUkJwKRvsb+HGdnH960yW2eB2byDFzlHWwuvWKXY7WA3FIJ6ifPbIVyrwj72iToiLxVllSiOTthG5/R9NPtBc6I+kmWvOpTyAtVwNgnNsMd0rX7nfDJsmz3VSO5RpZ3zC8HuJBjXk2SzaRcHZRic+N8g4aoJ0wVLKC5AcHfXVmiCWVJcB2yzIEEXk7UQE0PAV+/9s11i573he3ZlEFL/IuL1vKT2MXkRFHL4MXymoHdF67vNo= X-Forefront-PRVS: 0631F0BC3D X-Microsoft-Exchange-Diagnostics: 1;DB5PR02MB0776;23:FdM+lJD2Mo9swqRNHoYGqOqM+tdBzrM8LvcOjllDlCIcnu9289x5opu0ilJI74/09eUob9iZ57A35Vrg2OeQrWYfwwE5d+c6KHfrzcdhtd2O3VjBHvo85660gAGcHsPrONEs/BJDfTXCid46K+k5K+dQGmv4m0RuRN57k0vyZozZxcFG+PUt7kPFbjV99LS+m5S0yDzipO4wEfdm0G1wRE0A13tnX9RVTeolWNff+oIo6LZRhnE8M8HmhHW/Jbnkea5Y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nosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2015 20:21:01.6378 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR02MB0776 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3388 Lines: 78 v2: eliminate strscpy_truncate(); the single strscpy() API in v2 just tolerates a truncated string (while returning an error value) Also, improve some of the comparison language with strlcpy/strncpy. This patch series addresses limitations in strncpy() and strlcpy(); both the old APIs are unpleasant, as Linus nicely summarized here: https://lkml.org/lkml/2015/4/28/570 and of course as other folks (Greg K-H and Linus again) said last year: https://plus.google.com/+gregkroahhartman/posts/1amLbuhWbh5 The proposed new API (strscpy(), for "s"afe string copy) has an easy-to-use API for detecting buffer overflow, doesn't walk past the requested copy size on the source string, and isn't subject to thread-safety attacks like the current strlcpy implementation. See patch 2/3 for more on why strscpy() is a good thing. To make strscpy() work more efficiently I did the minimum tweaking necessary to allow to work on all architectures, though of course individual maintainers can still make their versions more efficient as needed. It's likely not necessary for per-architecture implementations of strscpy() to be written, but I stuck with the standard __HAVE_ARCH_XXX model just for consistency with the rest of . I tested the implementation with a simple user-space harness, so I believe it is correct for the corner cases I could think of. In particular I pairwise-tested all the unaligned values of source and dest, and tested the restriction on src page-crossing at all unaligned offsets approaching the page boundary. The patch series is available to be pulled from git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile.git strscpy Chris Metcalf (3): Make asm/word-at-a-time.h available on all architectures string: provide strscpy() tile: use global strscpy() rather than private copy arch/arc/include/asm/Kbuild | 1 + arch/avr32/include/asm/Kbuild | 1 + arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/Kbuild | 1 + arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/Kbuild | 1 + arch/m32r/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/Kbuild | 1 + arch/mn10300/include/asm/Kbuild | 1 + arch/nios2/include/asm/Kbuild | 1 + arch/powerpc/include/asm/Kbuild | 1 + arch/s390/include/asm/Kbuild | 1 + arch/score/include/asm/Kbuild | 1 + arch/tile/gxio/mpipe.c | 33 ++------------ arch/tile/include/asm/Kbuild | 1 + arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/Kbuild | 1 + arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/word-at-a-time.h | 80 ++++++++++++++++++++++++++++---- include/linux/string.h | 3 ++ lib/string.c | 88 ++++++++++++++++++++++++++++++++++++ 25 files changed, 188 insertions(+), 37 deletions(-) -- 2.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/