Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3664012pxb; Mon, 24 Jan 2022 14:48:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJznde2azrhtVYvQZpjUTRxAV+neFi0unfKbdtT5vJTP/yEIovKgzzqQehp/ez2Vjh+SF/Pz X-Received: by 2002:a63:6a49:: with SMTP id f70mr13211933pgc.244.1643064512404; Mon, 24 Jan 2022 14:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064512; cv=none; d=google.com; s=arc-20160816; b=Gu6Tcu0cX0KG8Jezx7VRf+REV40dXvD59Q2sgefpb0nDPDQIDThaHvngwZVIOIB4QX +GCNVotJHR7ZErZ1r3cyR0vt6Pl/sSaKsqdfv30x+9hBbPgDdW0V9efGeM/0zb2tBQvC hpGNWyRJuzathrmEb9uLn9viGRXvmo0LrClkXh5iN7wM8Pg77S+PWPJ2t9eqL8C57tHz BUxUqxNw4ekinRiK0+zJhSOBOEYyXBxxJEx4GCyI3fGxCBr/owzO0qAxf5ImgyQR46cr 8Eo1PpVQSQVXFdHipZb8TvgYXHSuhVhYlUUVSmPI/wSWeqGesoUf1EooDMN9zzFy6c4a zNJQ== 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=RarU5GufHTruHAFJuj/3OnRyOwGrgfUDU2qRKuIhw5A=; b=thzqvI6eqXW2S8HOVPWV+vZTD9XCErBm/ZRzryw7IemVwpzgZmwNc4Exk4bnerG7aF hs8TQk08ypZKoL+avkAzcn6zJe9B5OyImTnmW7Hh15meUIHbaiGecJq6lhnJFLTrRtsR et46PVK3OzkSrOlX1AiH6SPZT4dz0wG9A9GOVB6Q5idULGBroGqyNNsFSEce3Q4ieaov 9CpAm2YEMw8ASDtyBPwqaSZfUT5AoZhhYstMDBNiyucGdW7QPTZGVanRuykBcZIVAhjo MadJVWFEqcYICoUOorSdNAa5US/n5nT7dFQz2iSsmGsiIguALlfUBd1tE6MBTVCiVRaw Gp0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SpXQwbTL; 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 17si591503pjg.157.2022.01.24.14.48.20; Mon, 24 Jan 2022 14:48:32 -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=SpXQwbTL; 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 S1838502AbiAXWqm (ORCPT + 99 others); Mon, 24 Jan 2022 17:46:42 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:59074 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457174AbiAXVlH (ORCPT ); Mon, 24 Jan 2022 16:41:07 -0500 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 29D006151E; Mon, 24 Jan 2022 21:41:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3879EC340E4; Mon, 24 Jan 2022 21:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060466; bh=gZXY/vjiqQc7fhVYSbfkUerxw0714FNVQzxq8TQcFeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SpXQwbTL9v9pUkMYn52xWdtoYiyIgeYRBIRSIQ2xkur5+hp38X6HlYsEfWy/sTJNy NkNicLwdrTHV1l48mPTYVTqIrEwgRLyfoMmAiPl4GoTHddzgB1TF6dX0RmkDSZ5TST IpKmdQAHnRA66zW7gvY60c1uKsVh+sJCikmPtoEM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com, Andrii Nakryiko , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexei Starovoitov Subject: [PATCH 5.16 0940/1039] xdp: check prog type before updating BPF link Date: Mon, 24 Jan 2022 19:45:29 +0100 Message-Id: <20220124184156.881999296@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Toke Høiland-Jørgensen commit 382778edc8262b7535f00523e9eb22edba1b9816 upstream. The bpf_xdp_link_update() function didn't check the program type before updating the program, which made it possible to install any program type as an XDP program, which is obviously not good. Syzbot managed to trigger this by swapping in an LWT program on the XDP hook which would crash in a helper call. Fix this by adding a check and bailing out if the types don't match. Fixes: 026a4c28e1db ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link") Reported-by: syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com Acked-by: Andrii Nakryiko Signed-off-by: Toke Høiland-Jørgensen Link: https://lore.kernel.org/r/20220107221115.326171-1-toke@redhat.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9656,6 +9656,12 @@ static int bpf_xdp_link_update(struct bp goto out_unlock; } old_prog = link->prog; + if (old_prog->type != new_prog->type || + old_prog->expected_attach_type != new_prog->expected_attach_type) { + err = -EINVAL; + goto out_unlock; + } + if (old_prog == new_prog) { /* no-op, don't disturb drivers */ bpf_prog_put(new_prog);