From patchwork Mon Feb 18 23:23:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tobin C. Harding" X-Patchwork-Id: 10818941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34CE01399 for ; Mon, 18 Feb 2019 23:24:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2183E28706 for ; Mon, 18 Feb 2019 23:24:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154F128A3D; Mon, 18 Feb 2019 23:24:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 91CFE28706 for ; Mon, 18 Feb 2019 23:24:18 +0000 (UTC) Received: (qmail 26054 invoked by uid 550); 18 Feb 2019 23:24:15 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 25999 invoked from network); 18 Feb 2019 23:24:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=hNMkb4bQzXmhzFly4 1b0O1VF8jmcWk9234vaYcXiT5k=; b=HrgFS/uhpclN20gHq6RMtROZyPmPAqEu0 eExlNoL3NYneeWlZKL3VmAN6a0lHz2gGIBE3hnPNP+Bv3FcWv61xun1uPrwJd6xn pXC1JdR07fHqzvdJncK0QAQYUGYpzo1qqR3AO+7CiCQJBFX4+/tzECT5F9OMo+ZI TrrlweemTnbWZg8NFB93MVhwD0C4SqlB3oBJrB0/p70TDyMCTKdsgp64kfODTUe+ qZBd5Jf9I77mUZQjR6N6A3ySOoU8J4vs//7WXpGIvacZt5p7FBIuYCRI+7H73YMP /j0v0bhRCZ47rl/OZlowcGR39hNdQTdaCexS6EuUgOW2BoDFho4yg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtddvgddtjeculddtuddrgedtledrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpedfvfhosghinhcu vedrucfjrghrughinhhgfdcuoehtohgsihhnsehkvghrnhgvlhdrohhrgheqnecukfhppe duvddurdeggedrvddtvddrudeftdenucfrrghrrghmpehmrghilhhfrhhomhepthhosghi nheskhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: From: "Tobin C. Harding" To: Kees Cook Cc: "Tobin C. Harding" , Shuah Khan , Alexander Shishkin , Greg Kroah-Hartman , Andy Shevchenko , kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Subject: [PATCH 0/6] lib: Add safe string funtions Date: Tue, 19 Feb 2019 10:23:02 +1100 Message-Id: <20190218232308.11241-1-tobin@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP No file maintainer, CC'ing all those who touched this file :) And Shua for kselftest stuff. Hi Kess, During your talk at LCA you mentioned that we could do with a couple more safe string functions. One to zero the tail of the destination buffer after call to strscpy() and also the self explanatory strscpy_from_user(). Here is a patch set with my attempts to implement these two functions. While doing this I noticed that we have a test module for lib/string.c (lib/test_string.c) that is not tied into kselftest. So I enable this first up in patch 1. Patch 2 and 3 are function docstring cleanups. Patch 4 adds the copy and zero function, naming it strscpy_zeroed(). I'd love some help naming this better. Patch also adds test code. Patch 5 fixes function docstring to correctly document the behavior of strncpy_from_user(). Patch 6 adds strscpy_from_user(). Does not include test code. I had to do a bit of learning for getting the tests hooked into kselftest, I think its all correct. Module is built correctly when the config option is present and the tests run both via make -C tools/testing/selftests TARGETS=lib run_tests and via loading the module manually. As a side note, this series leaves tools/testing/selftests/lib with 4 shell scripts that are identical except the test name. We could probably do with refactoring them into a single script. Patchset introduces a checkpatch warning WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully I couldn't work out if this is a false positive or not? Does the new config option CONFIG_TEST_STRING need more documentation? I don't see where extra docs should be added and it seems self explanatory as is. thanks, Tobin. Tobin C. Harding (6): lib/string: Enable string selftesting lib/string: Fix erroneous 'overflow' documentation lib/string: Use correct docstring format lib/string: Add string copy/zero function lib: Fix function documentation for strncpy_from_user lib: Add function strscpy_from_user() include/linux/string.h | 4 ++ lib/Kconfig.debug | 14 +++++++ lib/Makefile | 2 +- lib/string.c | 41 ++++++++++++++---- lib/strncpy_from_user.c | 60 ++++++++++++++++++++++----- lib/test_string.c | 35 +++++++++++++++- tools/testing/selftests/lib/Makefile | 2 +- tools/testing/selftests/lib/config | 1 + tools/testing/selftests/lib/string.sh | 19 +++++++++ 9 files changed, 157 insertions(+), 21 deletions(-) create mode 100755 tools/testing/selftests/lib/string.sh