Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2657290pxa; Mon, 17 Aug 2020 15:43:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG2J+VlN665OAGV5E327Lsy63Mcbe7PYhXC5AnT3/Ov0ChRjTtnqIUsiyesxksbzw1fPDi X-Received: by 2002:a05:6402:1d25:: with SMTP id dh5mr16571433edb.266.1597704195716; Mon, 17 Aug 2020 15:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704195; cv=none; d=google.com; s=arc-20160816; b=p04KrDyRHi2LdML5i8Vqc1l9Y+PlriRl/uFu217hWdpiVazz8lfEKN9sCkLFCgkS/S ZJRvJytx49ZQvHAlqbsPL3TUk0F1Z6YpXph4JhCA9ZgNA0E7sHMPcR0iISF6xHolP6vv zHCcRTYiwvcLoqRmXKMXrQyCh8BTAhEt+2RjKb9IzPW/nFacfkJHA/8gCImXJYecJrkZ 67irfcawsk1EVSgwDQEVjIgxT4OT82CKGxK07Urmq2K3NlINgxloXAh/MdZRAPVWZBSN hx7sWP4M5Gj/EG1ci5ZqgGD8A3N6WEb2Ljo/NUI6SKHncYjr0wq7fj3wIqml1VsdliY4 KLYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N5QdLa9NihiPlbYqKaU1A11IQI23qSpoagyR4P/M8Mc=; b=r7w9Xh8z6W23dyNxO6gI0i9imiHxgjsbxYMWNos29NRDgXYWDy9pelwcx0EcR9mxVd VDCFbBAU1YFNz/RC2xkBSGLbH4HiFh5iiXkYsCXWrPQAmVllr/trYzHFCQwCEe3nclF0 hhRvZw+PU7AOcOnNnMdgxnjb4kFcp1lvJkWx5cnliw6Hlp3t8cufmhLZeSzrQ1DGk62B Gh0SGKtFHXWZT2yQ0pXgkoQ6bobK2+/A2AVZMdhUzGwJAr3+Znyzlk0vsRvDq2vhAwpu dPBTMrP59wOWsAmSea42L6PZmTLnYmo0u6Dxqk/CBQ+XiTqg/JtvE5Y0p4wHoLvWhckN gFig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bnb4Vp+5; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be24si11879065edb.287.2020.08.17.15.42.52; Mon, 17 Aug 2020 15:43:15 -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=@kernel.org header.s=default header.b=Bnb4Vp+5; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403819AbgHQSru (ORCPT + 99 others); Mon, 17 Aug 2020 14:47:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:43222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388013AbgHQPze (ORCPT ); Mon, 17 Aug 2020 11:55:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2C49B20760; Mon, 17 Aug 2020 15:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679733; bh=tOeoHQl/xkAbw98W/d/HbPYQ9y5YcAyc2aZjIwp5VYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bnb4Vp+5ldUZi3gCyZtTWslx0Nd4DcKd1FdSk4NXBe3A0waQSTYnaGbkqZNkVsKa4 Oi+CdkcsM5zVCAoeLJFvui3pR/Mo3eRLHzoLYKdC7G2XzwE8unT1WJ9Qf89AOSNPKN WamS4F4vQjeWYDVuAH2AFT6a60KRhmVPWuJF8RLI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Andy Lutomirski , "Chang S. Bae" , Andy Lutomirski , Borislav Petkov , Brian Gerst , Dave Hansen , Denys Vlasenko , "H. Peter Anvin" , Markus T Metzger , Peter Zijlstra , Ravi Shankar , Rik van Riel , Thomas Gleixner , Ingo Molnar , Linus Torvalds , Sasha Levin , Jann Horn Subject: [PATCH 5.7 315/393] x86/fsgsbase/64: Fix NULL deref in 86_fsgsbase_read_task Date: Mon, 17 Aug 2020 17:16:05 +0200 Message-Id: <20200817143834.887647766@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 8ab49526b53d3172d1d8dd03a75c7d1f5bd21239 ] syzbot found its way in 86_fsgsbase_read_task() and triggered this oops: KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] CPU: 0 PID: 6866 Comm: syz-executor262 Not tainted 5.8.0-syzkaller #0 RIP: 0010:x86_fsgsbase_read_task+0x16d/0x310 arch/x86/kernel/process_64.c:393 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 This can happen if ptrace() or sigreturn() pokes an LDT selector into FS or GS for a task with no LDT and something tries to read the base before a return to usermode notices the bad selector and fixes it. The fix is to make sure ldt pointer is not NULL. 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 Acked-by: 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: Markus T Metzger Cc: Peter Zijlstra Cc: Ravi Shankar Cc: Rik van Riel Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- arch/x86/kernel/process_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 5ef9d8f25b0e8..cf2cda72a75bf 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -315,7 +315,7 @@ static unsigned long x86_fsgsbase_read_task(struct task_struct *task, */ mutex_lock(&task->mm->context.lock); ldt = task->mm->context.ldt; - if (unlikely(idx >= ldt->nr_entries)) + if (unlikely(!ldt || idx >= ldt->nr_entries)) base = 0; else base = get_desc_base(ldt->entries + idx); -- 2.25.1