Re: [patch V2 14/16] x86/iopl: Restrict iopl() permission scope

From: Ingo Molnar
Date: Tue Nov 12 2019 - 01:32:59 EST



* Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:

> --- a/arch/x86/kernel/ioport.c
> +++ b/arch/x86/kernel/ioport.c
> @@ -18,12 +18,15 @@ static atomic64_t io_bitmap_sequence;
>
> void io_bitmap_share(struct task_struct *tsk)
> {
> - /*
> - * Take a refcount on current's bitmap. It can be used by
> - * both tasks as long as none of them changes the bitmap.
> - */
> - refcount_inc(&current->thread.io_bitmap->refcnt);
> - tsk->thread.io_bitmap = current->thread.io_bitmap;
> + /* Can be NULL when current->thread.iopl_emul == 3 */
> + if (current->thread.io_bitmap) {
> + /*
> + * Take a refcount on current's bitmap. It can be used by
> + * both tasks as long as none of them changes the bitmap.
> + */
> + refcount_inc(&current->thread.io_bitmap->refcnt);
> + tsk->thread.io_bitmap = current->thread.io_bitmap;
> + }

Minor side note: whitespace damage managed to slip in that code, see the
fix below.

Thanks,

Ingo

arch/x86/kernel/ioport.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index f87844e22ec9..ee37a1c25ecc 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -17,16 +17,16 @@
static atomic64_t io_bitmap_sequence;

void io_bitmap_share(struct task_struct *tsk)
- {
- /* Can be NULL when current->thread.iopl_emul == 3 */
- if (current->thread.io_bitmap) {
- /*
- * Take a refcount on current's bitmap. It can be used by
- * both tasks as long as none of them changes the bitmap.
- */
- refcount_inc(&current->thread.io_bitmap->refcnt);
- tsk->thread.io_bitmap = current->thread.io_bitmap;
- }
+{
+ /* Can be NULL when current->thread.iopl_emul == 3 */
+ if (current->thread.io_bitmap) {
+ /*
+ * Take a refcount on current's bitmap. It can be used by
+ * both tasks as long as none of them changes the bitmap.
+ */
+ refcount_inc(&current->thread.io_bitmap->refcnt);
+ tsk->thread.io_bitmap = current->thread.io_bitmap;
+ }
set_tsk_thread_flag(tsk, TIF_IO_BITMAP);
}