Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp649131pxa; Fri, 14 Aug 2020 14:03:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7mJZi/+HwbOxYLdbcQyWHMFIs7uX9omlDQtgdwB2F09nCWZr1q/yH/LI9AKlkMFyOHf01 X-Received: by 2002:a05:6402:206d:: with SMTP id bd13mr4188961edb.57.1597438980751; Fri, 14 Aug 2020 14:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597438980; cv=none; d=google.com; s=arc-20160816; b=ilBpiFRDDGiy7dzu91JmrePbxCe4gL79HF0LupYk+EWSxYjF2Khs7i+UpAH+w4zR8o aJRMwhF2HNh1AzgyYSDi8hI6LuUrJCPQrz062wI06k2Geg6Z7dsGDPOWjTBaW8vhxXOM GGgCaWYHm6aOKO0F717xREt0VjdhnlcG47rF5bbC7ETvvlCrWiuVxxCpgn0MxFrTC5ui 1T/1bbU89tFXb+I53oGVpeO9+GYEo0OOXutUzcWFwJDnbJ8Hxusmeq0H71zhdyICDWhY XGuvfNPwppDP7R9xaitpv1keH87rL3B5VrvQob6TY3UveYDSMofHR/qKk0nVAqvpDhVB og3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=FxfL4nNBtn83VJwRlrrSOfWZbqLm3WkoDXTSi56b1Aw=; b=g2UqYlXX+oaYtY5B9ZExV57s4bBx5o3DkABsv1Xhq51u9spADw+CJ3b5zY+0Ovfzz7 Yn3nHBpg3pmcye55b+QZuXM2uHp3sVpkUAzATdHP+4dZe9OjxBsBiPNMwFAqM+w1obu1 S+F+Yu7zJcilYjPwmF5/nVqFMUJtgY86aQngXvasbuNnL2PHgZtaF0sLLMacjGEqlgwy uoEceb1h/j6bOR3RRuU5Us+R4ghzmfOFnnPg+fC+vE2h2gpkyu9DLd9kIj8rj+jg38Ip FwtKL7Xnly8KUq/mUQW6bvhbf0rgfq1asZbOm2oVyxCtmF9YoZ504tmwEzo9LPQxRz/x +Nkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b="uGhj/C0d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i26si5922599edv.600.2020.08.14.14.02.37; Fri, 14 Aug 2020 14:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b="uGhj/C0d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727927AbgHNTDd (ORCPT + 99 others); Fri, 14 Aug 2020 15:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbgHNTDc (ORCPT ); Fri, 14 Aug 2020 15:03:32 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C84C061385 for ; Fri, 14 Aug 2020 12:03:32 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id y10so3026564plr.11 for ; Fri, 14 Aug 2020 12:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=FxfL4nNBtn83VJwRlrrSOfWZbqLm3WkoDXTSi56b1Aw=; b=uGhj/C0dfHB7n5e7xIx5kV1OYPEWOvCViVjH30qdyFEu7Bh7oHsXyeSLflm05F+MiD hz3uOPsd+7OG0nCIJ5YtqKQ5qquqtwieHcotkrFWEWXuMqMGg0bC5wYD2gr9cgz+0+gx ltMGaxOdARbFUgW8w6/3/PBMn244tPeUbOM+6W00xWphbtgyx2c6GeVHaupzcsUdqwEF z8ktfTCjuEr5Mv4VxgqjF9dfSd/laFDWbu9vM+LcXQXCv/Xic27/jVnZntuzq872sDJq /JUGYIGCerRplUGPcue1ruBDhR06qfs5++fA0YCEc04E9I6ZGMSrUSDOxc+CMhz2VZma NNfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=FxfL4nNBtn83VJwRlrrSOfWZbqLm3WkoDXTSi56b1Aw=; b=Fnut16nVsMszoXBTQPwoDvowxjUtP3kRnxaU4uxsJ8kbHT9q7scPhYtZNJgFRr7suB XM2fTjPu6ErqYesDCs9CKnICa9xJlHd56ZUFEmg6jdTH0UywssWyPgrBPipwmkbFo3LM ZXRPr5U2J6n9SXhASLie7fH0IFMrt0raIEzr98aeghHlVl0VoTUhBDVRQ2MkcWZkAEjH DqPFblMDbZu2MTqwIRkiKpD5hE72tdx1iMC92vn88K+/hJJJI2KTCO0LdwZQIyT1VrGG BSA1qLFlpWvEdB4U7SXt7PPaHt3HFcmhhG0NFVMlwfqQYF2//ZVNNQ9Xq6C287m5gn86 +Bzw== X-Gm-Message-State: AOAM5318A/rVHDMy9pZXSE+cb3pb2wSPyra0hEfXzpnhEm3o4m5bjCK7 P/FeQWbGBizjolS1kj+E/hwQ2A== X-Received: by 2002:a17:902:a404:: with SMTP id p4mr3105916plq.35.1597431809200; Fri, 14 Aug 2020 12:03:29 -0700 (PDT) Received: from ?IPv6:2601:646:c200:1ef2:3949:6711:2d80:a044? ([2601:646:c200:1ef2:3949:6711:2d80:a044]) by smtp.gmail.com with ESMTPSA id bv17sm8718663pjb.0.2020.08.14.12.03.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Aug 2020 12:03:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] x86/fsgsbase/64: Fix NULL deref in 86_fsgsbase_read_task Date: Fri, 14 Aug 2020 12:03:26 -0700 Message-Id: <784A8221-8E96-4C81-B218-4BC4960AA34A@amacapital.net> References: <20200814181617.442787-1-edumazet@google.com> Cc: Ingo Molnar , linux-kernel , Eric Dumazet , Jann Horn , syzbot , Andy Lutomirski , "Chang S . Bae" , Borislav Petkov , Brian Gerst , Dave Hansen , Denys Vlasenko , "H . Peter Anvin" , Linus Torvalds , Markus T Metzger , Peter Zijlstra , Ravi Shankar , Rik van Riel , Thomas Gleixner In-Reply-To: <20200814181617.442787-1-edumazet@google.com> To: Eric Dumazet X-Mailer: iPhone Mail (17G68) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Aug 14, 2020, at 11:16 AM, Eric Dumazet wrote: >=20 > =EF=BB=BFsyzbot found its way in 86_fsgsbase_read_task() [1] >=20 > Fix is to make sure ldt pointer is not NULL Acked-by: Andy Lutomirski Maybe add something like this to the changelog: This can happen if ptrace() or sigreturn() pokes an LDT selector into FS or G= S for a task with no LDT and something tries to read the base before a retur= n to usermode notices the bad selector and fixes it. I=E2=80=99ll see if I can whip up a test case too. >=20 > [1] > general protection fault, probably for non-canonical address 0xdffffc00000= 00001: 0000 [#1] PREEMPT SMP KASAN > KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] > CPU: 0 PID: 6866 Comm: syz-executor262 Not tainted 5.8.0-syzkaller #0 > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Go= ogle 01/01/2011 > RIP: 0010:x86_fsgsbase_read_task+0x16d/0x310 arch/x86/kernel/process_64.c:= 393 > Code: 3c 02 00 0f 85 7c 01 00 00 4c 8b a5 80 04 00 00 44 0f b7 eb 48 b8 00= 00 00 00 00 fc ff df 49 8d 7c 24 08 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c= 0 74 08 3c 03 0f 8e 30 01 00 00 45 3b 6c 24 08 0f > RSP: 0018:ffffc90001677db8 EFLAGS: 00010202 > RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 > RDX: 0000000000000001 RSI: 0000000000000008 RDI: 0000000000000008 > RBP: ffff88809eaf9780 R08: 0000000000000000 R09: ffff88809eaf9c17 > R10: ffffed1013d5f382 R11: 0000000000000000 R12: 0000000000000000 > R13: 0000000000000000 R14: 0000000000000000 R15: 0000000020000080 > FS: 0000000000000000(0000) GS:ffff8880ae600000(0063) knlGS:0000000009cf48= 40 > CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 > CR2: 0000000020000080 CR3: 000000009fa0d000 CR4: 00000000001506f0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > Call Trace: > putreg32+0x3ab/0x530 arch/x86/kernel/ptrace.c:876 > genregs32_set arch/x86/kernel/ptrace.c:1026 [inline] > genregs32_set+0xa4/0x100 arch/x86/kernel/ptrace.c:1006 > copy_regset_from_user include/linux/regset.h:326 [inline] > ia32_arch_ptrace arch/x86/kernel/ptrace.c:1061 [inline] > compat_arch_ptrace+0x36c/0xd90 arch/x86/kernel/ptrace.c:1198 > __do_compat_sys_ptrace kernel/ptrace.c:1420 [inline] > __se_compat_sys_ptrace kernel/ptrace.c:1389 [inline] > __ia32_compat_sys_ptrace+0x220/0x2f0 kernel/ptrace.c:1389 > do_syscall_32_irqs_on arch/x86/entry/common.c:84 [inline] > __do_fast_syscall_32+0x57/0x80 arch/x86/entry/common.c:126 > do_fast_syscall_32+0x2f/0x70 arch/x86/entry/common.c:149 > entry_SYSENTER_compat_after_hwframe+0x4d/0x5c > RIP: 0023:0xf7fe9569 > Code: 10 05 03 74 b8 01 10 06 03 74 b4 01 10 07 03 74 b0 01 10 08 03 74 d8= 01 00 00 00 00 00 00 00 00 00 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90 9= 0 90 90 eb 0d 90 90 90 90 90 90 90 90 90 90 90 90 > RSP: 002b:00000000ffd99e7c EFLAGS: 00000217 ORIG_RAX: 000000000000001a > RAX: ffffffffffffffda RBX: 000000000000000d RCX: 0000000000001ad1 > RDX: 0000000000000000 RSI: 0000000020000080 RDI: 0000000000001ad1 > RBP: 000000000000003c R08: 0000000000000000 R09: 0000000000000000 > R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 > R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 > Modules linked in: > ---[ end trace f79c8042700af7c5 ]--- > RIP: 0010:x86_fsgsbase_read_task+0x16d/0x310 arch/x86/kernel/process_64.c:= 393 > Code: 3c 02 00 0f 85 7c 01 00 00 4c 8b a5 80 04 00 00 44 0f b7 eb 48 b8 00= 00 00 00 00 fc ff df 49 8d 7c 24 08 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c= 0 74 08 3c 03 0f 8e 30 01 00 00 45 3b 6c 24 08 0f > RSP: 0018:ffffc90001677db8 EFLAGS: 00010202 > RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 > RDX: 0000000000000001 RSI: 0000000000000008 RDI: 0000000000000008 > RBP: ffff88809eaf9780 R08: 0000000000000000 R09: ffff88809eaf9c17 > R10: ffffed1013d5f382 R11: 0000000000000000 R12: 0000000000000000 > R13: 0000000000000000 R14: 0000000000000000 R15: 0000000020000080 > FS: 0000000000000000(0000) GS:ffff8880ae600000(0063) knlGS:0000000009cf48= 40 > CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 > CR2: 0000000020000080 CR3: 000000009fa0d000 CR4: 00000000001506f0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >=20 > Fixes: 07e1d88adaae ("x86/fsgsbase/64: Fix ptrace() to read the FS/GS base= accurately") > Co-developed-by: Jann Horn > Signed-off-by: Eric Dumazet > Reported-by: syzbot > Cc: Andy Lutomirski > Cc: Chang S. Bae > Cc: Andy Lutomirski > Cc: Borislav Petkov > Cc: Brian Gerst > Cc: Dave Hansen > Cc: Denys Vlasenko > Cc: H. Peter Anvin > Cc: Linus Torvalds > Cc: Markus T Metzger > Cc: Peter Zijlstra > Cc: Ravi Shankar > Cc: Rik van Riel > Cc: Thomas Gleixner > Cc: Ingo Molnar > --- > arch/x86/kernel/process_64.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index d6f946707270e41d4aa04e4069b1b4eb82afd687..8393ee1aa9c89b3712b7aef510= 149d73762ef314 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -390,7 +390,7 @@ unsigned long x86_fsgsbase_read_task(struct task_struc= t *task, > */ > mutex_lock(&task->mm->context.lock); > ldt =3D task->mm->context.ldt; > - if (unlikely(idx >=3D ldt->nr_entries)) > + if (unlikely(ldt =3D=3D NULL || idx >=3D ldt->nr_entries)) > base =3D 0; > else > base =3D get_desc_base(ldt->entries + idx); > --=20 > 2.28.0.220.ged08abb693-goog >=20