Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp861372pxb; Tue, 1 Feb 2022 11:59:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW/0wQDOw7y8TIoTfa6NI+F2FvBjBJSRHAX3E7w6oilP0rkylhjT309g9YiGF1dEYytHTe X-Received: by 2002:a05:6402:4305:: with SMTP id m5mr26689224edc.342.1643745555104; Tue, 01 Feb 2022 11:59:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745555; cv=none; d=google.com; s=arc-20160816; b=xHjsO0Fehv2vbUzwwx55IJLXFod+PhH8fsiY0TuIkth2VYxzqbJo9/LBuiMk/qUiJS hFuFBbTYR67qWVqXbIxN1K//b2lsGMMiqLIxI4lC73pljMkoQFVnMofxIcvTshRIJ4Vk upk/nYJF41vqotmhSA7qpRWPw4dicIAooW7+W4BrEtV+VpS9s4kXhposcHVG6WEn8JU4 qgipHebCi/GeGE6E0TduyrVT+OZhs1U8fUcLmAYIhwtMehLDvq/tIdLQypiZ4TnO15II mrYn/p1KSaPZfiXJdYA8R2j3YfItdcGE7BxHk/njLD3eKg8R6Z5niR+rPTKDFmTl8CV5 neig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J3Ufc4eBjVxWXBkQv6h86qxx61nN2EmubAaj+GasV0E=; b=clsp5s1VFWjSb2PdjQ4WM46gPz9YsV367t1tsfVj6qqQ0S39st/p/YVvK9sFHUYcCJ dSTaSfRVpfYIS2dtR1chdndF2XqUu0DMyVJxCnBkgtFvQYvACxtRot7unsHzX2Cs0zF1 VPZ1q/LIAv8cNOnKTwxRnZAV9YKUEFTki7q8LLEKPi7NnZHPF1e5IY4pfM9v947euTH/ pypRVWj/YLfkwub5QiSo1EvlpU0J15n6Y06PVNbpZiREmquqhFD56vOxVxdKcIuIJjqr 7k73+dybSJlQ6TurgJmrPAM/rBen0jZft/+4fKfa5HLFePOB9xPLWdcENClCtzRK+J4w I3ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2jd52qGa; 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=pass (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 he10si9790467ejc.936.2022.02.01.11.58.49; Tue, 01 Feb 2022 11:59:15 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=2jd52qGa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359167AbiAaLGm (ORCPT + 99 others); Mon, 31 Jan 2022 06:06:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358325AbiAaLDn (ORCPT ); Mon, 31 Jan 2022 06:03:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F37C06173E; Mon, 31 Jan 2022 03:03:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 249AA604F5; Mon, 31 Jan 2022 11:03:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED652C340E8; Mon, 31 Jan 2022 11:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643626984; bh=6eerhe6GybZvHheLPKe41Qbtj3MPhuJL4PFcSgB4LXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2jd52qGaPbJLm8q6z+l7rvBtO7NAG9xL9whBdgxmtviehfFlDVHG2b28jeBfICuwz jCxFS+Y4gu28OLgViSnah9rJuCQH3+us4Js6MJx/OD/SRoInbE9nfNZ0eFdZfMAIah Ew0/iwnvZ+4fSbu9ebSl/TWqQH62/Ut+6IaofjLk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , Daniel Borkmann , Michael Ellerman Subject: [PATCH 5.10 007/100] bpf: Guard against accessing NULL pt_regs in bpf_get_task_stack() Date: Mon, 31 Jan 2022 11:55:28 +0100 Message-Id: <20220131105220.683243480@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naveen N. Rao commit b992f01e66150fc5e90be4a96f5eb8e634c8249e upstream. task_pt_regs() can return NULL on powerpc for kernel threads. This is then used in __bpf_get_stack() to check for user mode, resulting in a kernel oops. Guard against this by checking return value of task_pt_regs() before trying to obtain the call chain. Fixes: fa28dcb82a38f8 ("bpf: Introduce helper bpf_get_task_stack()") Cc: stable@vger.kernel.org # v5.9+ Signed-off-by: Naveen N. Rao Acked-by: Daniel Borkmann Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/d5ef83c361cc255494afd15ff1b4fb02a36e1dcf.1641468127.git.naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/stackmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -664,13 +664,14 @@ BPF_CALL_4(bpf_get_task_stack, struct ta u32, size, u64, flags) { struct pt_regs *regs; - long res; + long res = -EINVAL; if (!try_get_task_stack(task)) return -EFAULT; regs = task_pt_regs(task); - res = __bpf_get_stack(regs, task, NULL, buf, size, flags); + if (regs) + res = __bpf_get_stack(regs, task, NULL, buf, size, flags); put_task_stack(task); return res;