Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp239813pxb; Wed, 18 Nov 2020 03:20:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlPbNDvxUaWdQTlzr2nKNuhk6rAULe+BzFUaTPO31qrJ9HEf8QQlKlJgRMXq6vBR58mIGi X-Received: by 2002:aa7:dd17:: with SMTP id i23mr24559265edv.276.1605698459291; Wed, 18 Nov 2020 03:20:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605698459; cv=none; d=google.com; s=arc-20160816; b=S4cxxk6BCgUJPAgZm2INL1zRn0SZ3urqDkDX2AO/Zvaf8zQ0Tlm+C1xABSrPZfQ/Tr WjpTO9uIGtCMkcH7JDm8nt1dz+PS5QepCbim1tuIDz1oHizowjk50Lmo4Ji3kkXEkzVm eAG17DLhU/BGExu/CiCuJsvE43dVSGGmrhT+IwBPR/7rk/b2dJD5PkGGE/LVnyfsQ9Yn vx8GKF3gATenN6i0OxC7mvGF9aZe8MQd6lXNmyRz23dZgJDwKIBqSQ+fb79tL4NmzBn0 e3zu30z0woUZhSbNw9ZGzjvXNgkUVHZcwj/GAwDzRLKUCiBk9eWiiEiyJ2v7LYjbrDFs +99Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pRohe2wpPXolmMdvR/at0ovtLoyHsrhZfm/U2gcuOco=; b=FP1pQPSjcVGPO8jmg6uB3G0mhdCFApyowqaBD0Z6uhPDExIXYvhAtWvydAN1cXe8pG JSuRm0Qt8fdwMy9EXym33+RgzE/YnfSq13qwv80UmsLz0Thhh4qtHl+00TsS3BsJnj/0 ssGp1bkvkP5L5/srWp7QTjivU3SajoA+q96uCvQfcdJ9kfoaf4VIO51VUGS4S5EAMBHj qkR2o9mPrcoRsYUl2eV1bx4y/K06yL4oztaN1mmR4sHHzkh/qnOSJ5yO4jhHLMEvY+hw tNDJ1nHSSDeFZgKh9y039iHUriDC7BP9ny+yPhEz2AjFxEysR//MthPiKBiRFBgJMmyt PtFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@privacyrequired.com header.s=stigmate header.b=ULcHjlhq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si5181844edx.521.2020.11.18.03.20.37; Wed, 18 Nov 2020 03:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@privacyrequired.com header.s=stigmate header.b=ULcHjlhq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727789AbgKRLRJ (ORCPT + 99 others); Wed, 18 Nov 2020 06:17:09 -0500 Received: from latitanza.investici.org ([82.94.249.234]:45377 "EHLO latitanza.investici.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726188AbgKRLRI (ORCPT ); Wed, 18 Nov 2020 06:17:08 -0500 X-Greylist: delayed 560 seconds by postgrey-1.27 at vger.kernel.org; Wed, 18 Nov 2020 06:17:07 EST 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.20.1