Message ID | 20230109163906.706000-1-fred@cloudflare.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2257582wrt; Mon, 9 Jan 2023 08:43:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXs4VfVoaVqzGsova6CiHfICwopFwben3JwkZ0HEWBE2qLWMfkWS1exiBIn4J3frHZG+6EoF X-Received: by 2002:a17:902:d887:b0:185:441e:2dda with SMTP id b7-20020a170902d88700b00185441e2ddamr84850312plz.44.1673282612971; Mon, 09 Jan 2023 08:43:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673282612; cv=none; d=google.com; s=arc-20160816; b=uDwQKLFtSktZ/1uaZ1ZlEP/97CFbSfywytU9Fz+ZZ1/sEiLr2b2A+OoatB4v+R5bpH /dnLce/rFd0uCX1JEmPWH3vH5mqoEenQ26IvK8hPkriKOxNsrit2WCoOWijDLj2RS4/7 8DNgxW3ZBS5qMVol6bqVWjUoNzIaGm90WW5GO7NYnCtFRYcwkbyJ8TVYbfoi40ONo2sN UFDZcahi0SPeGmIrWK+5HwJErVmb+W4XqCrQcOB6Tx5TrEbYTKBxd+Ub2dMCalcQIpd8 t0vQflVLD/ZmgTyGAwAyApCHsNxyDMAA5Bo9rbhFnltVb+uG1tj2KgmsX1MjGmjQqwyb +Z0g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Xrg136BCp0PmT+E9WTU4STUIwjfV5DcN5FDK70FqYcI=; b=L6z+Cqm/eYtMLmNW88RzHW2H9rTy0SFb5AGkJdT7Lf8pUbSsjYrUF3ZuimZrrjBHoY t4HbB3dQx4YY4TKDvccxw2UwmUM71wC5+r2jHDpMj97GHSRHqw0jXEGdrhKf1knWy+fO 4Utr+Qly11my+sJHycnBMVMkF1UWSwYDcmJ81kuCA5SR+dQMdw8qDO8YjWXLnxA2przE 5q1m9vnIdlLwSzPLAxrvnclmu4OwhL3brIhnbNKqtdoi89bMcSSmwi39hJFOO2nm+IbL YUXoAdwK13FKJa+xtPkTVd3jaNJzeX1CSohjnsXcbCxa07MuPIU4yOLk29yWQyawJNqK SpAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=aIFfWS0c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r3-20020a632b03000000b004792b0801f3si10224596pgr.558.2023.01.09.08.43.20; Mon, 09 Jan 2023 08:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=aIFfWS0c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbjAIQji (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Mon, 9 Jan 2023 11:39:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234470AbjAIQja (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 11:39:30 -0500 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8691F34D67 for <linux-kernel@vger.kernel.org>; Mon, 9 Jan 2023 08:39:28 -0800 (PST) Received: by mail-il1-x12a.google.com with SMTP id h26so5084443ila.11 for <linux-kernel@vger.kernel.org>; Mon, 09 Jan 2023 08:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Xrg136BCp0PmT+E9WTU4STUIwjfV5DcN5FDK70FqYcI=; b=aIFfWS0cT4UCU3f6+rKm+5rHYgjr2Tnu5w/qCdXoxWFfN6ueukXs1tp/iAqvpFruK7 6tN75Q/bqrlviXjadh9+tAa31LXc9OPq9r3CqA566MBQTvoURfX3gKuDU8AqrQDRBhyZ c06SMvz82ThLUp5ehRVxJiZtnjJqPdFRKpKEA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Xrg136BCp0PmT+E9WTU4STUIwjfV5DcN5FDK70FqYcI=; b=JAK58c7xrXxFX6nB52hKckYRnk8p29E3t+P28iDKRifAMw57O/eMbKHFIRadfkdyYu JUgE1NbVOjWjJpkyi9mT6AuxLrqwAmkwxNrAPHxvlT1mqtgDJkGsLhfxDFH3mVKS+Yxb V9ZQyuWYTuj6aAkDupdg315K6Yk2S2smI0WMRmssNVew0uMF9FsRO/3TEg2cIaaH9EJp RXSNYy4DFqY5VqcZBpbnLRyA0BhF0w7Lyb6CL/zlFx8iw2XMx/9tteiAqfwDcGk8I7uQ 25TkaXE1f5e5urwHYP4Btg1ZtnQtiH3gIE4iUKuq4airkQrTgxhFVuD0uP8xX/PXF/98 VpLw== X-Gm-Message-State: AFqh2kpals7aZwH2kB6SE2DP8Xvz7Z4uNQ4Fnb1theflOZeFHI5bJhKV IvOEM9qpJwWQSsVyy8Py6R00mg== X-Received: by 2002:a05:6e02:2205:b0:30d:92c4:8d6 with SMTP id j5-20020a056e02220500b0030d92c408d6mr9444298ilf.10.1673282367876; Mon, 09 Jan 2023 08:39:27 -0800 (PST) Received: from localhost.localdomain ([70.57.89.124]) by smtp.gmail.com with ESMTPSA id w17-20020a92ad11000000b0030c44ed932asm2790684ilh.29.2023.01.09.08.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 08:39:27 -0800 (PST) From: Frederick Lawler <fred@cloudflare.com> To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, kuba@kernel.org, linux-kernel@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, zymon.heidrich@gmail.com, phil@nwl.cc, netdev@vger.kernel.org, kernel-team@cloudflare.com, Frederick Lawler <fred@cloudflare.com>, stable@vger.kernel.org, Jakub Sitnicki <jakub@cloudflare.com> Subject: [PATCH net] net: sched: disallow noqueue for qdisc classes Date: Mon, 9 Jan 2023 10:39:06 -0600 Message-Id: <20230109163906.706000-1-fred@cloudflare.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754563988977863292?= X-GMAIL-MSGID: =?utf-8?q?1754563988977863292?= |
Series |
[net] net: sched: disallow noqueue for qdisc classes
|
|
Commit Message
Frederick Lawler
Jan. 9, 2023, 4:39 p.m. UTC
While experimenting with applying noqueue to a classful queue discipline, we discovered a NULL pointer dereference in the __dev_queue_xmit() path that generates a kernel OOPS: # dev=enp0s5 # tc qdisc replace dev $dev root handle 1: htb default 1 # tc class add dev $dev parent 1: classid 1:1 htb rate 10mbit # tc qdisc add dev $dev parent 1:1 handle 10: noqueue # ping -I $dev -w 1 -c 1 1.1.1.1 [ 2.172856] BUG: kernel NULL pointer dereference, address: 0000000000000000 [ 2.173217] #PF: supervisor instruction fetch in kernel mode ... [ 2.178451] Call Trace: [ 2.178577] <TASK> [ 2.178686] htb_enqueue+0x1c8/0x370 [ 2.178880] dev_qdisc_enqueue+0x15/0x90 [ 2.179093] __dev_queue_xmit+0x798/0xd00 [ 2.179305] ? _raw_write_lock_bh+0xe/0x30 [ 2.179522] ? __local_bh_enable_ip+0x32/0x70 [ 2.179759] ? ___neigh_create+0x610/0x840 [ 2.179968] ? eth_header+0x21/0xc0 [ 2.180144] ip_finish_output2+0x15e/0x4f0 [ 2.180348] ? dst_output+0x30/0x30 [ 2.180525] ip_push_pending_frames+0x9d/0xb0 [ 2.180739] raw_sendmsg+0x601/0xcb0 [ 2.180916] ? _raw_spin_trylock+0xe/0x50 [ 2.181112] ? _raw_spin_unlock_irqrestore+0x16/0x30 [ 2.181354] ? get_page_from_freelist+0xcd6/0xdf0 [ 2.181594] ? sock_sendmsg+0x56/0x60 [ 2.181781] sock_sendmsg+0x56/0x60 [ 2.181958] __sys_sendto+0xf7/0x160 [ 2.182139] ? handle_mm_fault+0x6e/0x1d0 [ 2.182366] ? do_user_addr_fault+0x1e1/0x660 [ 2.182627] __x64_sys_sendto+0x1b/0x30 [ 2.182881] do_syscall_64+0x38/0x90 [ 2.183085] entry_SYSCALL_64_after_hwframe+0x63/0xcd ... [ 2.187402] </TASK> Previously in commit d66d6c3152e8 ("net: sched: register noqueue qdisc"), NULL was set for the noqueue discipline on noqueue init so that __dev_queue_xmit() falls through for the noqueue case. This also sets a bypass of the enqueue NULL check in the register_qdisc() function for the struct noqueue_disc_ops. Classful queue disciplines make it past the NULL check in __dev_queue_xmit() because the discipline is set to htb (in this case), and then in the call to __dev_xmit_skb(), it calls into htb_enqueue() which grabs a leaf node for a class and then calls qdisc_enqueue() by passing in a queue discipline which assumes ->enqueue() is not set to NULL. Fix this by not allowing classes to be assigned to the noqueue discipline. Linux TC Notes states that classes cannot be set to the noqueue discipline. [1] Let's enforce that here. Links: 1. https://linux-tc-notes.sourceforge.net/tc/doc/sch_noqueue.txt Fixes: d66d6c3152e8 ("net: sched: register noqueue qdisc") Cc: stable@vger.kernel.org Signed-off-by: Frederick Lawler <fred@cloudflare.com> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> --- net/sched/sch_api.c | 5 +++++ 1 file changed, 5 insertions(+)
Comments
Hello: This patch was applied to netdev/net.git (master) by Jakub Kicinski <kuba@kernel.org>: On Mon, 9 Jan 2023 10:39:06 -0600 you wrote: > While experimenting with applying noqueue to a classful queue discipline, > we discovered a NULL pointer dereference in the __dev_queue_xmit() > path that generates a kernel OOPS: > > # dev=enp0s5 > # tc qdisc replace dev $dev root handle 1: htb default 1 > # tc class add dev $dev parent 1: classid 1:1 htb rate 10mbit > # tc qdisc add dev $dev parent 1:1 handle 10: noqueue > # ping -I $dev -w 1 -c 1 1.1.1.1 > > [...] Here is the summary with links: - [net] net: sched: disallow noqueue for qdisc classes https://git.kernel.org/netdev/net/c/96398560f26a You are awesome, thank you!
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 2317db02c764..72d2c204d5f3 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1133,6 +1133,11 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, return -ENOENT; } + if (new && new->ops == &noqueue_qdisc_ops) { + NL_SET_ERR_MSG(extack, "Cannot assign noqueue to a class"); + return -EINVAL; + } + err = cops->graft(parent, cl, new, &old, extack); if (err) return err;