From patchwork Sat Jul 29 12:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13333142 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22A841643B for ; Sat, 29 Jul 2023 12:32:28 +0000 (UTC) Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B32C2D71 for ; Sat, 29 Jul 2023 05:32:26 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-768054797f7so252843885a.2 for ; Sat, 29 Jul 2023 05:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1690633945; x=1691238745; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZU0afenvFJMfep7in4CutaC38zgJ4hrc4NI08nas3YE=; b=4sSseOJaGwrHQJcyu63vTO1fwIadcNt3Xc+1vJp6rmUVv9YlwBjkiWirDxVuOclZEN 5Frg86Mf60wdlaJZXNfI2mR5SIzs883ygJNkWhSUTisMvn545l8SE5GPZBrqt3q3gjB+ TZySN550n+RBJB0YHCTiT7/vh6ZOxvpsomzySIPXm43F2xMUQZbkyGL91+Yu7b6vyvzU 8GkI7JqkPwtGpGmscENACK94INe9bYpID8L+RaPB15ieTkKRqrjjoytnqWRKoZeDlpyU fQzGMTk9ukpnShI8c5KpfvUsZV5F6hBpP6GvP3efyanKqA2SzKZ7u1ce7sP5JlF80Fds yQPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690633945; x=1691238745; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZU0afenvFJMfep7in4CutaC38zgJ4hrc4NI08nas3YE=; b=PJIPQHHPzNhzQKaZaJujpX2ycdpOufagdzE3/ddLfA6cT+4ZmEs37ozQu0LEnjKiqS aNOlfU7tBFrU1IDr8Ac3jFC6gWqGwBBEJB7p8ezLqfo4aYR6JzGNuMANvAqFV2bK6I02 +IPFaYY+BUnQzBhofAowm+32ffSdnSJFeRQNV6mACNMtzovB7hvmusdK+cBxpDJaiDoz sDz2CAFqdaY0tHBBasX7LcR+9HbhllkUyQkIm1MPw3NgoVuCRiG7psk14H7MwqHFmeGy efwvM6qy3uFR2Fsp/1+Tcacdr/KvbPpgl25cj37mfFpxH9VcNpHks7OFFUAabemCeldV xsxQ== X-Gm-Message-State: ABy/qLbtmzON6qpdho4GgXN9Z+Zi6VtrKJsVukZiGVH3uci9jlTSrmZE cDJwsDOZkNu0Co/Ur3OwqR/s4A== X-Google-Smtp-Source: APBJJlFyjbtSWX4rGsjPSN48BRV0zA7+My3BBt8E2xEX+EcKPJCCTg+gQNNcnf4gxDmB4dLgwuGfVQ== X-Received: by 2002:a05:620a:d81:b0:767:e04c:8d6e with SMTP id q1-20020a05620a0d8100b00767e04c8d6emr5534328qkl.51.1690633945537; Sat, 29 Jul 2023 05:32:25 -0700 (PDT) Received: from majuu.waya ([142.114.148.137]) by smtp.gmail.com with ESMTPSA id x12-20020a0ce0cc000000b006263c531f61sm2024716qvk.24.2023.07.29.05.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jul 2023 05:32:25 -0700 (PDT) From: Jamal Hadi Salim To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com Cc: jiri@resnulli.us, xiyou.wangcong@gmail.com, netdev@vger.kernel.org, sec@valis.email, ramdhan@starlabs.sg, billy@starlabs.sg, Jamal Hadi Salim Subject: [PATCH net v2 1/3] net/sched: cls_u32: No longer copy tcf_result on update to avoid use-after-free Date: Sat, 29 Jul 2023 08:32:00 -0400 Message-Id: <20230729123202.72406-2-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230729123202.72406-1-jhs@mojatatu.com> References: <20230729123202.72406-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: valis When u32_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter. This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free. Fix this by no longer copying the tcf_result struct from the old filter. Fixes: de5df63228fc ("net: sched: cls_u32 changes to knode must appear atomic to readers") Reported-by: valis Reported-by: M A Ramdhan Signed-off-by: valis Signed-off-by: Jamal Hadi Salim --- net/sched/cls_u32.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 907e58841fe8..da4c179a4d41 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -826,7 +826,6 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp, new->ifindex = n->ifindex; new->fshift = n->fshift; - new->res = n->res; new->flags = n->flags; RCU_INIT_POINTER(new->ht_down, ht); From patchwork Sat Jul 29 12:32:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13333144 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 128E1168CE for ; Sat, 29 Jul 2023 12:32:29 +0000 (UTC) Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 596182D7D for ; Sat, 29 Jul 2023 05:32:27 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3a3efebcc24so2356805b6e.1 for ; Sat, 29 Jul 2023 05:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1690633946; x=1691238746; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bzpcxfJtg9C/S41DIrYk7rj68a4zxIEDEj2VNXRtGHU=; b=2GIRFCmIxAfPNEpPYzHiP0XYAvHbZ/irqVfPTyYgH0J1aBZC1rqm1HDbNrktefDVqt hYu+YmGjt9/zy4DFaxbsvmWzW22bp5if1tH43ENumYKC5ZTFtjuz6fyiTXfiCAncqe0i CmfmM1KxiP17pCFv2loYKwh7YCSN6Pkt2ryRtpDEcc30lY8zOtB1VlWazj1o/5OH0+ET E9Qyy8TCOYUJhHTUT7BFPdf+CkvzvF/S5uRSa2H6z2kCb1O8/CBiRUg7ZMBOH1dpk5Ck M0YimobpVeSBdQnBjkvE35p6mQvWUGWXccfFVWDYCKDX02bAyrOjAKKeh/dhB5SF23zQ sl0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690633946; x=1691238746; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bzpcxfJtg9C/S41DIrYk7rj68a4zxIEDEj2VNXRtGHU=; b=JCFR/T0HkBmE5tD9Bh0iV5GmmRGQiyZxpC4RsdiGvTdQEP9uyflpfbpGswZjwBn80F DmQYCAL0w7xoe5zQhNPP87QrwlsqIy/5f8VQHni6LBWo5FQ6yW+0atH9Nm+dyzGoCuLP UpyccNVdrGj3QT5MQvZXa623eTXTgHuEK8SQ4VOHsNrFxYTMEVRoelzBX/Dss1TkMsD7 y6wQGyZ3pT8s8GlqHcbLWOaJSCuDq5i6GahRxiICjpeQrk/NhyAZi850lh29lXsokSki sU084mWwWKO/AU/tnPdWrvhdKo40weJmZveoVldPJSISRtUOIyuyDXGSMAnv1QjuRBpU XOzA== X-Gm-Message-State: ABy/qLZIV8dnhs+rGAhy3/8Gqu9b06JJAGqaZfHESmMPn6HlWNtTnpJN o21eq1LeTKrReUrxtJXlqvQDdA== X-Google-Smtp-Source: APBJJlHoVHJMhcgRakhF9q8fvl0YCY2SPAA7TPujyNKb8lllkM1Yq1YtjrMRWlRvNeDhnHXWHcAOuw== X-Received: by 2002:a05:6808:3023:b0:3a3:6c7d:a5cb with SMTP id ay35-20020a056808302300b003a36c7da5cbmr6382405oib.46.1690633946630; Sat, 29 Jul 2023 05:32:26 -0700 (PDT) Received: from majuu.waya ([142.114.148.137]) by smtp.gmail.com with ESMTPSA id x12-20020a0ce0cc000000b006263c531f61sm2024716qvk.24.2023.07.29.05.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jul 2023 05:32:26 -0700 (PDT) From: Jamal Hadi Salim To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com Cc: jiri@resnulli.us, xiyou.wangcong@gmail.com, netdev@vger.kernel.org, sec@valis.email, ramdhan@starlabs.sg, billy@starlabs.sg, Jamal Hadi Salim Subject: [PATCH net v2 2/3] net/sched: cls_fw: No longer copy tcf_result on update to avoid use-after-free Date: Sat, 29 Jul 2023 08:32:01 -0400 Message-Id: <20230729123202.72406-3-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230729123202.72406-1-jhs@mojatatu.com> References: <20230729123202.72406-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: valis When fw_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter. This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free. Fix this by no longer copying the tcf_result struct from the old filter. Fixes: e35a8ee5993b ("net: sched: fw use RCU") Reported-by: valis Reported-by: Bing-Jhong Billy Jheng Signed-off-by: valis Signed-off-by: Jamal Hadi Salim --- net/sched/cls_fw.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index 8641f8059317..c49d6af0e048 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -267,7 +267,6 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, return -ENOBUFS; fnew->id = f->id; - fnew->res = f->res; fnew->ifindex = f->ifindex; fnew->tp = f->tp; From patchwork Sat Jul 29 12:32:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13333143 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F858168AD for ; Sat, 29 Jul 2023 12:32:29 +0000 (UTC) Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC8E2D71 for ; Sat, 29 Jul 2023 05:32:28 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-63cf28db24cso17936966d6.2 for ; Sat, 29 Jul 2023 05:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1690633948; x=1691238748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lngQvXDPyBuidB6/rPDqoDNpZHxGFh1LY55Kja1Ci+c=; b=kVz+HhdvU8n1EdvpHUeTb1vj22dyzO8ERJeAYsmNoQNlPVoRFKfS4ljGM2z99DMU7E m2h+WcFLMus92gNRspvTa59a/jgIM7JiDESO+SzlvyrXwnZCTlPYkkzkEVr1xSsJRMbK cU0apEiUmHznp013jmXec5Ut3Ww2GuHAoqxByIzNwG9C9RZz3nT1fkYWjreDlaK6Krg7 nAgAk+1Pm6MCf3rjYDXp/pbbkUTjub86eqi3zT0ry6T6fWEMUFLjf9BM4p3mAR5mTz7J I3a6LNhx84HCkIkxHAF4y8jznOS8n6/k4Q75J4q0OI17ZCnsYKua5IxFZ5CjKD+eKBCQ 09ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690633948; x=1691238748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lngQvXDPyBuidB6/rPDqoDNpZHxGFh1LY55Kja1Ci+c=; b=QtdrF/+ZPs1zw3dQQ7Xlaw+93M33Yc0KB7yz2p9LenTEI09tNbKoUIhhBQE4GG/U9B ZB5nFxYe5feRvp3vIQ9aQcoT5WLhF41DNKG+zIVcKdbAIXSr8yX7+QIwrDE/ILrUlR4N 25xJnWzwDnSsCdBjWqBL2IaWEHpcuVExCKcJJqxPFZtrsVc6P/8QHqNPOvb3Fpn9VIkZ clto11bQ3yxll8RWSo9U43nSx+A3rckwfm6Nsi+8WRydjdHbJTy2lhyh5YzpodF6TZT9 XuVhXKi3gNILMoeDdFBnG7ybQgAQJwhggh14Xq3XmmAZPPEvMdkIA59VgRE3wML+VowZ b1rQ== X-Gm-Message-State: ABy/qLagafDXvofiE7oH9uyJC2o3SGWzypDdoOhUkjJF+SJoBbw9Ibb/ WXcL7DDvL2iaZW/2x+0rXuvYug== X-Google-Smtp-Source: APBJJlFJ+L2ujJF1WF7HhhCZGJIRYzUOF4m3om0qiyL9BVTpQj9EbxXrezrDVZi0AQS2HkkEOt162Q== X-Received: by 2002:a0c:f4c3:0:b0:636:79d1:d5a7 with SMTP id o3-20020a0cf4c3000000b0063679d1d5a7mr5797409qvm.47.1690633947791; Sat, 29 Jul 2023 05:32:27 -0700 (PDT) Received: from majuu.waya ([142.114.148.137]) by smtp.gmail.com with ESMTPSA id x12-20020a0ce0cc000000b006263c531f61sm2024716qvk.24.2023.07.29.05.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jul 2023 05:32:27 -0700 (PDT) From: Jamal Hadi Salim To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com Cc: jiri@resnulli.us, xiyou.wangcong@gmail.com, netdev@vger.kernel.org, sec@valis.email, ramdhan@starlabs.sg, billy@starlabs.sg, Jamal Hadi Salim Subject: [PATCH net v2 3/3] net/sched: cls_route: No longer copy tcf_result on update to avoid use-after-free Date: Sat, 29 Jul 2023 08:32:02 -0400 Message-Id: <20230729123202.72406-4-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230729123202.72406-1-jhs@mojatatu.com> References: <20230729123202.72406-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: valis When route4_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter. This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free. Fix this by no longer copying the tcf_result struct from the old filter. Fixes: 1109c00547fc ("net: sched: RCU cls_route") Reported-by: valis Reported-by: Bing-Jhong Billy Jheng Signed-off-by: valis Signed-off-by: Jamal Hadi Salim --- net/sched/cls_route.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index d0c53724d3e8..1e20bbd687f1 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -513,7 +513,6 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, if (fold) { f->id = fold->id; f->iif = fold->iif; - f->res = fold->res; f->handle = fold->handle; f->tp = fold->tp;