mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keerthana Kalyanasundaram <keerthanak@vmware.com>
To: "keescook@chromium.org" <keescook@chromium.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Alexey Makhalov <amakhalov@vmware.com>,
	Ajay Kaher <akaher@vmware.com>,
	Vasavi Sirnapalli <vsirnapalli@vmware.com>
Subject: Re: PROBLEM: Using Randomize structure layout GCC plugin doesn't generate proper debuginfo
Date: Thu, 25 May 2023 10:32:53 +0000	[thread overview]
Message-ID: <15A87C96-F904-4B59-939B-80653410A56E@vmware.com> (raw)
In-Reply-To: <DF6066B2-35AE-40BE-A217-D3C48DBF6751@vmware.com>

Please find the sample C program and script below.

Sample C program (filename: test.c)

struct cpu_info {
	float first;
	char second;
	union {
		int cap[5];
		long align_var;
	};
} __attribute__((__designated_init__)) __attribute__((randomize_layout));
int main(void)
{
	struct cpu_info boot_cpu_data = {
			.first = 10,
			.second = 11,
			.cap = {1,2,3,4,5},
	};
	return 0;
}
...

Script to compile the C file with randstruct plugin (filename: test.sh)

#!/bin/sh

assert_command_true()
{
    local command=$1
    local output=
    output="$(eval "$1")"
    if [ $? -ne 0 ]; then
       echo "$command FAILED!!"
       exit 1
    fi
}

echo "DOWNLOAD RANDSTRUCT PLUGIN CODE"
assert_command_true "curl -k -o randomize_layout_plugin.c https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/randomize_layout_plugin.c?h=linux-6.3.y"
assert_command_true "curl -k -o gcc-common.h https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/gcc-common.h?h=linux-6.3.y"
assert_command_true "curl -k -o gcc-generate-gimple-pass.h https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/gcc-generate-gimple-pass.h?h=linux-6.3.y"
assert_command_true "curl -k -o gcc-generate-ipa-pass.h https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/gcc-generate-ipa-pass.h?h=linux-6.3.y"
assert_command_true "curl -k -o gcc-generate-rtl-pass.h https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/gcc-generate-rtl-pass.h?h=linux-6.3.y"
assert_command_true "curl -k -o gcc-generate-simple_ipa-pass.h https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h?h=linux-6.3.y"

echo "COMPILE RANDSTRUCT PLUGIN"
gcc_version=$(gcc -dumpversion)
assert_command_true "g++ -Wall -O2 -fPIC -Wno-unused-variable -DPLUGIN_VERSION='\"6.3.y\"' -I /usr/lib/gcc/x86_64-unknown-linux-gnu/${gcc_version}/plugin/include -std=gnu++11 -fno-rtti -fno-exceptions -fasynchronous-unwind-tables -ggdb -Wno-narrowing -Wno-unused-variable -Wno-format-diag -shared -o randomize_layout_plugin.so randomize_layout_plugin.c"

echo "COMPILE test.c WITH RANDSTRUCT PLUGIN"
assert_command_true "gcc -g -DRANDSTRUCT -fplugin=./randomize_layout_plugin.so -fplugin-arg-randomize_layout_plugin-performance-mode -c -o test-randstruct.o test.c"

echo "COMPILE test.c WIHTOUT RANDSTRUCT PLUGIN"
assert_command_true "gcc -g -c -o test-no-randstruct.o test.c"

echo "INSPECT OBJDUMP"
assert_command_true "gdb test-randstruct.o -q -ex='set pagination off' -ex='ptype struct cpu_info' -ex q | tail -n +2 > struct-cpu_info-randstruct"
assert_command_true "gdb test-no-randstruct.o -q -ex='set pagination off' -ex='ptype struct cpu_info' -ex q | tail -n +2 > struct-cpu_info-no-randstruct"
assert_command_true "diff struct-cpu_info-randstruct struct-cpu_info-no-randstruct”

...

Randseed (filename: randomize_layout_seed.h)

const char *randstruct_seed = "8d01fec380b70520c9f1ec333231021e1d04f8fb64c858f7333187e79ee2111f”;


Thanks
Keerthana



> On 25-May-2023, at 3:51 PM, Keerthana Kalyanasundaram <keerthanak@vmware.com> wrote:
> 
> Hello,
> 
> I’m reporting this bug in randomize strcture layout plugin in GCC plugins code of linux kernel tree.
> When I compile the kernel with randomize structure layout GCC plugin, the resulting debuginfo does not have the randomised structures.
> 
> To reproduce this, I have a C sample program and a script to compile the program with and without randomize_layout_plugin
> from linux kernel, the resulted debuginfo in both cases are same. Though the plugin shuffles the structure members, the resulting debuginfo 
> has unshuffled structure.
> 
> I have found an old bug in GCC reporting the same https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84052 This bug has been closed as invalid though there was a conversation between PaX maintainers and GCC devs.
> 
> I assume this issue has been there since the randomize_layout_plugin has been added in kernel. Please correct me if I’m wrong.
> 
> Please let me know, if you need more information. I hope you are able to fix this issue.
> 
> Thanks
> Keerthana




  reply	other threads:[~2023-05-25 10:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 10:21 Keerthana Kalyanasundaram
2023-05-25 10:32 ` Keerthana Kalyanasundaram [this message]
2023-05-25 15:14 ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15A87C96-F904-4B59-939B-80653410A56E@vmware.com \
    --to=keerthanak@vmware.com \
    --cc=akaher@vmware.com \
    --cc=amakhalov@vmware.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vsirnapalli@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®