Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3685313pxb; Mon, 24 Jan 2022 15:18:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaFIl77UbHe8aKVM8MC2iLIadstEUiLMVKdX9qPI9KhIvwm9tTfQgTMrFcJrNckrz6Abko X-Received: by 2002:a17:902:bb87:b0:148:a2e7:fb52 with SMTP id m7-20020a170902bb8700b00148a2e7fb52mr16565330pls.147.1643066333649; Mon, 24 Jan 2022 15:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643066333; cv=none; d=google.com; s=arc-20160816; b=PFZFmiKHe7FLVMt8b4YQIdrUkLls11MwUagfUkYUw3yxke9sWy4tfTm9bxC3gAqeie 3vx3Vt3Xu138LJgHMpjg3lYCFLGW/fVhgcPl40hVPRU/O7TglBnf551tE4lshBZrFl4n EB6hCcNxzu60PPbbjePTY2lkKPS6DbL7+cpkwyMXFTtG1NvDeT2M28YIqhxLlXZwCaRC r0OApRiv1VZHvF2t7FQLya1UyqVlww2Z5gjqlfGgZ1iCpKTBkI9PV4lodqF2hFQbOnev 69p+qVAdc2093E7cdCkYi7cTnvQ6ninVJ6K88UZim1AALQhDsac9ZAitT6Mgwzf8Emta G3Ng== 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=rhTcARvo2n0FEqipO/NaUsEvpEBV77pwEz8RS6f2T3E=; b=DY7jvfVnIcoCr1e88fR2v/XqMWDomup4VYQ3yKYvDStEcv31/G9n9oDj9PS6GVm/RT d21Im4LYi0kel2be56XkA6oquPRKipwNnLhf/Y1gtt13Fda8owFjFvkaBRbxdXWAxZFa lAUZsT8zsgFPOuny8q6DezXk6dzDsQglubNeSSBEb6/RpQIuofBYndePmzjlO73aNF26 kGgsATQgGTEg2u237ibLVEwH6aBZMDm4+r7i89A5d/IuR2v4F7mvS0TWhY8xGRiWRwJA 4db55mBX6v6IfHPfRyk3a3AlOg6wsIBhoJ7AFNZiJAFhNd2gz4Avc54IxcvvgG3UYJh2 aVmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wvnd/UBa"; 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 mi11si676171pjb.124.2022.01.24.15.18.42; Mon, 24 Jan 2022 15:18:53 -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="wvnd/UBa"; 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 S1846689AbiAXXQo (ORCPT + 99 others); Mon, 24 Jan 2022 18:16:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1583235AbiAXWR1 (ORCPT ); Mon, 24 Jan 2022 17:17:27 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34BBC06138E; Mon, 24 Jan 2022 12:48:13 -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 ams.source.kernel.org (Postfix) with ESMTPS id B272DB81063; Mon, 24 Jan 2022 20:48:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA344C340E5; Mon, 24 Jan 2022 20:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057291; bh=PJBaakTJqJ7uadR58mhjBkXOGvr1mslmS/bj9utbnjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wvnd/UBaVYIVaeVW/saZtL0wHhQCZlQrfTUgB5dy1z7P7t19+83K14ibXq93m//Lj eB6tAGiFDJLyECektxeXiXP+2tjkrGzP6cjWlmpI+SibtF/Da7h1Wowvifvv+uwhMd IyZ4KHeJuIDNCJIiKu0WK6VuqFqswQlay6GeoQIY= 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.15 765/846] xdp: check prog type before updating BPF link Date: Mon, 24 Jan 2022 19:44:42 +0100 Message-Id: <20220124184127.349600297@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 @@ -9636,6 +9636,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);