From patchwork Wed Nov 18 11:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 11914801 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=-15.7 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 17229C5519F for ; Wed, 18 Nov 2020 11:07:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C3BCA223C7 for ; Wed, 18 Nov 2020 11:07:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=privacyrequired.com header.i=@privacyrequired.com header.b="ULcHjlhq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3BCA223C7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=privacyrequired.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0C3296B0036; Wed, 18 Nov 2020 06:07:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 073B96B005C; Wed, 18 Nov 2020 06:07:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA42F6B0068; Wed, 18 Nov 2020 06:07:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id B8E386B0036 for ; Wed, 18 Nov 2020 06:07:45 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 61EB88249980 for ; Wed, 18 Nov 2020 11:07:45 +0000 (UTC) X-FDA: 77497263690.02.truck36_070165427339 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 4777C10097AA1 for ; Wed, 18 Nov 2020 11:07:45 +0000 (UTC) X-HE-Tag: truck36_070165427339 X-Filterd-Recvd-Size: 3495 Received: from latitanza.investici.org (latitanza.investici.org [82.94.249.234]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Nov 2020 11:07:44 +0000 (UTC) Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id 4Cbg5B6LrHz8sh0; Wed, 18 Nov 2020 11:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=privacyrequired.com; s=stigmate; t=1605697662; bh=pRohe2wpPXolmMdvR/at0ovtLoyHsrhZfm/U2gcuOco=; h=From:To:Cc:Subject:Date:From; b=ULcHjlhqS7tEyxvDIdLm53xZYmh18NOkJmka/k9b5EZG1tIW1LZDa8wFvZoF4wgLM tnhC8hKV7+kgqbHvFZuhl2tFpqz9ruQPPWtN6VFjO03GnaIiHyUkN+p2fg56jXX9Yu 1jMRh6w9IioF7zEjfvnlTIf4mUjqne5QxBvt2QU4= Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: laniel_francis@privacyrequired.com) by localhost (Postfix) with ESMTPSA id 4Cbg5B0w7fz8sgF; Wed, 18 Nov 2020 11:07:41 +0000 (UTC) From: laniel_francis@privacyrequired.com To: akpm@linux-foundation.org Cc: linux-hardening@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dja@axtens.net, keescook@chromium.org, Francis Laniel Subject: [PATCH v5 0/5] Fortify strscpy() Date: Wed, 18 Nov 2020 12:07:26 +0100 Message-Id: <20201118110731.15833-1-laniel_francis@privacyrequired.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Francis Laniel Hi. I hope your families, friends and yourselves are fine. This patch set answers to this issue: https://github.com/KSPP/linux/issues/46 I based my modifications on top of two patches from Daniel Axtens which modify calls to __builtin_object_size to ensure the true size of char * are returned and not the surrounding structure size. To sum up, in my first patch I implemented a fortified version of strscpy. This new version ensures the following before calling vanilla strscpy: 1. There is no read overflow because either size is smaller than src length or we shrink size to src length by calling fortified strnlen. 2. There is no write overflow because we either failed during compilation or at runtime by checking that size is smaller than dest size. The second patch brings a new file in LKDTM driver to test this new version. The test ensures the fortified version still returns the same value as the vanilla one while panic'ing when there is a write overflow. The third just corrects some typos in LKDTM related file. If you see any problem or way to improve the code, feel free to share it. Best regards. Daniel Axtens (2): string.h: detect intra-object overflow in fortified string functions lkdtm: tests for FORTIFY_SOURCE Francis Laniel (3): string.h: Add FORTIFY coverage for strscpy() Add new file in LKDTM to test fortified strscpy. Correct wrong filenames in comment. drivers/misc/lkdtm/Makefile | 1 + drivers/misc/lkdtm/bugs.c | 50 +++++++++++++++ drivers/misc/lkdtm/core.c | 3 + drivers/misc/lkdtm/fortify.c | 82 +++++++++++++++++++++++++ drivers/misc/lkdtm/lkdtm.h | 19 +++--- include/linux/string.h | 75 ++++++++++++++++++---- tools/testing/selftests/lkdtm/tests.txt | 1 + 7 files changed, 213 insertions(+), 18 deletions(-) create mode 100644 drivers/misc/lkdtm/fortify.c