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 9C95DC4332F for ; Wed, 13 Oct 2021 07:23:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68C9C610D0 for ; Wed, 13 Oct 2021 07:23:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbhJMH0A (ORCPT ); Wed, 13 Oct 2021 03:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238237AbhJMHZ5 (ORCPT ); Wed, 13 Oct 2021 03:25:57 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12C5C061749 for ; Wed, 13 Oct 2021 00:23:54 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id k26so1664202pfi.5 for ; Wed, 13 Oct 2021 00:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=a+STDQupphuK/7Y3WCz3HFR7aiY2eZV5V/OCb+gsLGo=; b=I6w+qFwPBk9quxtMfcJjbCISh5NslqMD7RdikCpk68hT3HijzJ6U/NXdwAKbOum8vu vS3MxhZN9eoIgGDE3MBgTwkD9wwygGF3hFe/u5FZ9aYt5bDUp5/SKHaBIb9JSSrj/Eo+ hIxM+4qao33lcbsDFkeMBUVK1pi5/3teC4vZw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=a+STDQupphuK/7Y3WCz3HFR7aiY2eZV5V/OCb+gsLGo=; b=UreU5unLaw1bXh7dQ3Heuh2CzPYm4RZUM+b1srYeuNhUgPIhN46Zah07LlKjtEVcDq R063/z5b+ztDDIXwFjxtU0JExL14LMv35GgnbvuBb8wrCr4CldECgVlA/jey3DN59WXQ BTfK/iMq5oGTbf0x7w1RWuVXL6O+S3PN1FmzoolPODB9L6jL+ZulgeJ1yMXD+eDZUQTI Q4bvF7vh0wj61tynDQsVLFSYBnYe70FhItLRmT6ZxtaVBG1tiOYmR9EwrDYDZf+p5zZW 3VugFcITZWdhxHY768CRKF6iFvCT0k5u8udhu4dtWpR/ATExc72BP4BW5zowdMIZAGPt G6jg== X-Gm-Message-State: AOAM531VVxiECiko2xqEqmEP7/QuX1S9F0+BbYxBcQU2iYIU3qsT+2jJ yc3bCIV4rkWtm69yuTM/PCc9qw== X-Google-Smtp-Source: ABdhPJwUdjDXsZD6PJOkAL4X8A7lF2TLTDyO8KSYEbRyWhK7gdzTiI5rlXDwv4Yr1q/D3xOPKfxUmw== X-Received: by 2002:a63:6c89:: with SMTP id h131mr16767067pgc.47.1634109834205; Wed, 13 Oct 2021 00:23:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t125sm3280014pfc.119.2021.10.13.00.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 00:23:53 -0700 (PDT) Date: Wed, 13 Oct 2021 00:23:53 -0700 From: Kees Cook To: Christophe Leroy 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 Subject: Re: [PATCH v1 09/10] lkdtm: Fix lkdtm_EXEC_RODATA() Message-ID: <202110130018.7B2129375@keescook> References: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org On Mon, Oct 11, 2021 at 05:25:36PM +0200, Christophe Leroy wrote: > Behind a location, lkdtm_EXEC_RODATA() executes a real function, > not a copy of do_nothing(). > > So do it directly instead of using execute_location(). > > And fix displayed addresses by dereferencing the function descriptors. > > Signed-off-by: Christophe Leroy > --- > drivers/misc/lkdtm/perms.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c > index 442d60ed25ef..da16564e1ecd 100644 > --- a/drivers/misc/lkdtm/perms.c > +++ b/drivers/misc/lkdtm/perms.c > @@ -153,7 +153,14 @@ void lkdtm_EXEC_VMALLOC(void) > > void lkdtm_EXEC_RODATA(void) > { > - execute_location(lkdtm_rodata_do_nothing, CODE_AS_IS); > + pr_info("attempting ok execution at %px\n", > + dereference_symbol_descriptor(do_nothing)); > + do_nothing(); > + > + pr_info("attempting bad execution at %px\n", > + dereference_symbol_descriptor(lkdtm_rodata_do_nothing)); > + lkdtm_rodata_do_nothing(); > + pr_err("FAIL: func returned\n"); > } (In re-reading this more carefully, I see now why kallsyms.h is used earlier: _function_ vs _symbol_ descriptor.) In the next patch: static noinline void execute_location(void *dst, bool write) { ... func = setup_function_descriptor(&fdesc, dst); if (IS_ERR(func)) return; pr_info("attempting bad execution at %px\n", dst); func(); pr_err("FAIL: func returned\n"); } What are the conditions for which dereference_symbol_descriptor works but dereference _function_descriptor doesn't? -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Date: Wed, 13 Oct 2021 07:23:53 +0000 Subject: Re: [PATCH v1 09/10] lkdtm: Fix lkdtm_EXEC_RODATA() Message-Id: <202110130018.7B2129375@keescook> List-Id: References: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> In-Reply-To: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christophe Leroy 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 On Mon, Oct 11, 2021 at 05:25:36PM +0200, Christophe Leroy wrote: > Behind a location, lkdtm_EXEC_RODATA() executes a real function, > not a copy of do_nothing(). > > So do it directly instead of using execute_location(). > > And fix displayed addresses by dereferencing the function descriptors. > > Signed-off-by: Christophe Leroy > --- > drivers/misc/lkdtm/perms.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c > index 442d60ed25ef..da16564e1ecd 100644 > --- a/drivers/misc/lkdtm/perms.c > +++ b/drivers/misc/lkdtm/perms.c > @@ -153,7 +153,14 @@ void lkdtm_EXEC_VMALLOC(void) > > void lkdtm_EXEC_RODATA(void) > { > - execute_location(lkdtm_rodata_do_nothing, CODE_AS_IS); > + pr_info("attempting ok execution at %px\n", > + dereference_symbol_descriptor(do_nothing)); > + do_nothing(); > + > + pr_info("attempting bad execution at %px\n", > + dereference_symbol_descriptor(lkdtm_rodata_do_nothing)); > + lkdtm_rodata_do_nothing(); > + pr_err("FAIL: func returned\n"); > } (In re-reading this more carefully, I see now why kallsyms.h is used earlier: _function_ vs _symbol_ descriptor.) In the next patch: static noinline void execute_location(void *dst, bool write) { ... func = setup_function_descriptor(&fdesc, dst); if (IS_ERR(func)) return; pr_info("attempting bad execution at %px\n", dst); func(); pr_err("FAIL: func returned\n"); } What are the conditions for which dereference_symbol_descriptor works but dereference _function_descriptor doesn't? -- Kees Cook 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 9F309C433EF for ; Wed, 13 Oct 2021 07:24:39 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C5034604DA for ; Wed, 13 Oct 2021 07:24:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C5034604DA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HTkYx26dkz30Jj for ; Wed, 13 Oct 2021 18:24:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=I6w+qFwP; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=chromium.org (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=keescook@chromium.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=I6w+qFwP; dkim-atps=neutral Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HTkYC5kWMz2xtQ for ; Wed, 13 Oct 2021 18:23:57 +1100 (AEDT) Received: by mail-pf1-x42a.google.com with SMTP id g14so1692041pfm.1 for ; Wed, 13 Oct 2021 00:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=a+STDQupphuK/7Y3WCz3HFR7aiY2eZV5V/OCb+gsLGo=; b=I6w+qFwPBk9quxtMfcJjbCISh5NslqMD7RdikCpk68hT3HijzJ6U/NXdwAKbOum8vu vS3MxhZN9eoIgGDE3MBgTwkD9wwygGF3hFe/u5FZ9aYt5bDUp5/SKHaBIb9JSSrj/Eo+ hIxM+4qao33lcbsDFkeMBUVK1pi5/3teC4vZw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=a+STDQupphuK/7Y3WCz3HFR7aiY2eZV5V/OCb+gsLGo=; b=Yz03afsNmPc+lyObfTnbFKoCuFY0G0mZcgglanZzncUppgMXwbkZbmksNdyK2+UUJC L4a/TMIVShMBBB4RKiYOBQKcNL1m/NEfffUjssyfz4ASqlsF2jv7m3B69UixE9DEgCrB 0PMZNTG3fKNjt81vfkRwqIwpefLmeP/0zAWPIvXvgF+uNmsi3xPlnhq2nDty9Z+dv7r4 zn48dAV7E8Ri3iliYeGp91tCFQua8w82H6A3aWcmBhz+fVHNR4fArm/aNbGYJWdWRVYv IlJdAQ3TcD6+c1blEyHp1P7Lc83WtHYtfhmaQnob+6bBHtVhDBXTf5esvZnb/SZQ9J+a cdqA== X-Gm-Message-State: AOAM530YJ9dI41GsuLcfK5IOOGpBbmk+l+Ye5hHU8195RxHUsyIWZivy nTbvAl+Sj6A5M25oeLo+zaqMug== X-Google-Smtp-Source: ABdhPJwUdjDXsZD6PJOkAL4X8A7lF2TLTDyO8KSYEbRyWhK7gdzTiI5rlXDwv4Yr1q/D3xOPKfxUmw== X-Received: by 2002:a63:6c89:: with SMTP id h131mr16767067pgc.47.1634109834205; Wed, 13 Oct 2021 00:23:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t125sm3280014pfc.119.2021.10.13.00.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 00:23:53 -0700 (PDT) Date: Wed, 13 Oct 2021 00:23:53 -0700 From: Kees Cook To: Christophe Leroy Subject: Re: [PATCH v1 09/10] lkdtm: Fix lkdtm_EXEC_RODATA() Message-ID: <202110130018.7B2129375@keescook> References: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7da92e59e148bd23564d63bdd8bcfaba0ba6d1f1.1633964380.git.christophe.leroy@csgroup.eu> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Arnd Bergmann , Greg Kroah-Hartman , Helge Deller , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , linux-mm@kvack.org, Paul Mackerras , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Oct 11, 2021 at 05:25:36PM +0200, Christophe Leroy wrote: > Behind a location, lkdtm_EXEC_RODATA() executes a real function, > not a copy of do_nothing(). > > So do it directly instead of using execute_location(). > > And fix displayed addresses by dereferencing the function descriptors. > > Signed-off-by: Christophe Leroy > --- > drivers/misc/lkdtm/perms.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c > index 442d60ed25ef..da16564e1ecd 100644 > --- a/drivers/misc/lkdtm/perms.c > +++ b/drivers/misc/lkdtm/perms.c > @@ -153,7 +153,14 @@ void lkdtm_EXEC_VMALLOC(void) > > void lkdtm_EXEC_RODATA(void) > { > - execute_location(lkdtm_rodata_do_nothing, CODE_AS_IS); > + pr_info("attempting ok execution at %px\n", > + dereference_symbol_descriptor(do_nothing)); > + do_nothing(); > + > + pr_info("attempting bad execution at %px\n", > + dereference_symbol_descriptor(lkdtm_rodata_do_nothing)); > + lkdtm_rodata_do_nothing(); > + pr_err("FAIL: func returned\n"); > } (In re-reading this more carefully, I see now why kallsyms.h is used earlier: _function_ vs _symbol_ descriptor.) In the next patch: static noinline void execute_location(void *dst, bool write) { ... func = setup_function_descriptor(&fdesc, dst); if (IS_ERR(func)) return; pr_info("attempting bad execution at %px\n", dst); func(); pr_err("FAIL: func returned\n"); } What are the conditions for which dereference_symbol_descriptor works but dereference _function_descriptor doesn't? -- Kees Cook