From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D55EC4332F for ; Wed, 13 Oct 2021 07:29:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C3B861039 for ; Wed, 13 Oct 2021 07:29:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C3B861039 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A444D940009; Wed, 13 Oct 2021 03:29:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F4A4940007; Wed, 13 Oct 2021 03:29:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E2EC940009; Wed, 13 Oct 2021 03:29:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 81531940007 for ; Wed, 13 Oct 2021 03:29:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 30FB9182F2B06 for ; Wed, 13 Oct 2021 07:29:56 +0000 (UTC) X-FDA: 78690589992.20.5596429 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf18.hostedemail.com (Postfix) with ESMTP id AC83C4002087 for ; Wed, 13 Oct 2021 07:29:55 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4HTkh172KBz9sST; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8P4NSX8HwSC7; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4HTkh160rrz9sSS; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B6CEE8B77E; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id RP-ZD3PoBsMw; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [172.25.230.103]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 93FBA8B763; Wed, 13 Oct 2021 09:29:53 +0200 (CEST) Subject: Re: [PATCH v1 08/10] lkdtm: Really write into kernel text in WRITE_KERN To: Kees Cook Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Andrew Morton , "James E.J. Bottomley" , Helge Deller , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org References: <624940395e5d81967246f911a65740b9a15b5a70.1633964380.git.christophe.leroy@csgroup.eu> <202110130004.880A6C841@keescook> From: Christophe Leroy Message-ID: <336f314c-2db3-0899-b012-18c493ae0e3a@csgroup.eu> Date: Wed, 13 Oct 2021 09:29:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <202110130004.880A6C841@keescook> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr-FR X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AC83C4002087 X-Stat-Signature: swamewjgk8u5iuomcnpgkcouuzqkzbn4 Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1634110195-827239 Content-Transfer-Encoding: quoted-printable 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: Le 13/10/2021 =C3=A0 09:05, Kees Cook a =C3=A9crit=C2=A0: > On Mon, Oct 11, 2021 at 05:25:35PM +0200, Christophe Leroy wrote: >> WRITE_KERN is supposed to overwrite some kernel text, namely >> do_overwritten() function. >> >> But at the time being it overwrites do_overwritten() function >> descriptor, not function text. >> >> Fix it by dereferencing the function descriptor to obtain >> function text pointer. >> >> And make do_overwritten() noinline so that it is really >> do_overwritten() which is called by lkdtm_WRITE_KERN(). >> >> Signed-off-by: Christophe Leroy >> --- >> drivers/misc/lkdtm/perms.c | 8 +++++--- >> 1 file changed, 5 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c >> index 60b3b2fe929d..442d60ed25ef 100644 >> --- a/drivers/misc/lkdtm/perms.c >> +++ b/drivers/misc/lkdtm/perms.c >> @@ -5,6 +5,7 @@ >> * even non-readable regions. >> */ >> #include "lkdtm.h" >> +#include >=20 > Why not #include instead here? dereference_symbol_descriptor() is defined in linux/kallsyms.h >=20 >> #include >> #include >> #include >> @@ -37,7 +38,7 @@ static noinline void do_nothing(void) >> } >> =20 >> /* Must immediately follow do_nothing for size calculuations to work= out. */ >> -static void do_overwritten(void) >> +static noinline void do_overwritten(void) >> { >> pr_info("do_overwritten wasn't overwritten!\n"); >> return; >> @@ -113,8 +114,9 @@ void lkdtm_WRITE_KERN(void) >> size_t size; >> volatile unsigned char *ptr; >> =20 >> - size =3D (unsigned long)do_overwritten - (unsigned long)do_nothing; >> - ptr =3D (unsigned char *)do_overwritten; >> + size =3D (unsigned long)dereference_symbol_descriptor(do_overwritten= ) - >> + (unsigned long)dereference_symbol_descriptor(do_nothing); >> + ptr =3D dereference_symbol_descriptor(do_overwritten); >=20 > But otherwise, yup, I expect there will be a bunch of things like this > to clean up in LKDTM. :| Sorry about that! >=20 > Acked-by: Kees Cook >=20 >> =20 >> pr_info("attempting bad %zu byte write at %px\n", size, ptr); >> memcpy((void *)ptr, (unsigned char *)do_nothing, size); >> --=20 >> 2.31.1 >> >=20