From: David Laight <David.Laight@ACULAB.COM>
To: "'Preble, Adam C'" <adam.c.preble@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: How do I force an IBT trap in a demo kernel module?
Date: Wed, 24 May 2023 08:00:36 +0000 [thread overview]
Message-ID: <82034ea784e44c5b929f519ceac6c4e0@AcuMS.aculab.com> (raw)
In-Reply-To: <PH7PR11MB65237A81D8258BB1E10969A9A9409@PH7PR11MB6523.namprd11.prod.outlook.com>
From: Preble, Adam C
> Sent: 23 May 2023 20:29
>
> I am debugging why a kernel module of ours triggers the IBT (Indirect Branch Tracking) trap, and while
> doing that, I was trying to write a standalone demo that would forcefully trigger it on purpose. This
> has turned out to be much more difficult than I thought! What can I do to get a module to generate an
> indirect branch without an endbr64? Creating the indirect branch itself doesn't appear to be hard:
>
> 1. Set up a function call
> 2. Assign it to a function pointer
> 3. Call the function pointer
> 4. ...maybe add a compiler flag so it doesn't optimize the call to a direct branch.
>
> I am primarily building in a Debian environment with gcc (Debian 10.2.1-6) 10.2.1 20210110. By
> default, the branch does get optimized away. I had to set the -mforce-indirect-call flag. The endbr64
> instruction would still emit so I added a function attribute to suppress it:
...
> So what do I have to do to tell objtool to allow to me deliberately shoot myself in the foot here?
You could try adjusting the function pointer by the size of the endbr64 instrauction.
Oh, put the function pointer variable into static data.
That should stop it all being optimised away.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-05-24 8:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 19:28 How do I force an IBT trap in a demo kernel module? Preble, Adam C
2023-05-24 8:00 ` David Laight [this message]
2023-05-27 22:40 ` Pavel Machek
2023-05-31 23:02 ` Preble, Adam C
2023-06-01 8:04 ` David Laight
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=82034ea784e44c5b929f519ceac6c4e0@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=adam.c.preble@intel.com \
--cc=linux-kernel@vger.kernel.org \
/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