Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2142397pxb; Fri, 25 Mar 2022 11:51:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmS56Kd4swz03oJIC5fLWT2h7xMKmO17vIAwK2MDqh9FD99vJHpNXRWDhLtz3O3YxNx2gp X-Received: by 2002:a63:4602:0:b0:381:f916:9312 with SMTP id t2-20020a634602000000b00381f9169312mr740708pga.473.1648234264262; Fri, 25 Mar 2022 11:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648234264; cv=none; d=google.com; s=arc-20160816; b=pMW/Syd1Y4IlxPDu7VQBaJTCmE2vraN4aMjgqhX8df89N0TFKuCjpxIIb+wozV/OI8 hN9ZQ1LrGO6oAVMxko9OeqRe22eorrCXHTiAAuCxh65svH6zZmk/uoUMnGzqnDue9mOS qtY45en/8b/3k+1GKXh66XI6IYCDH9y7PFJSavtcm2sfgLQt+ky6n6XHkn0vSHktzuRd Wrubo10aiLRs2gc1hcKjMuwR7d+TCH0ifudD5/3NsZqQHo//c5a9lbhnS0aHDjhjopi5 hPmAYkQMaXIZCD3Ej5o2KzrHFNBPX6P/iVhma3AFrGNMV6uYJnL1OMgaf+Uipabww6MD j5UQ== 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=9KNZhr7cjjLCyHuNBb/mlakzWocklFA1Q2ELX6Jyh0U=; b=CgJblLuDw2AA59ZlfPKafvfh+dFcr8Y+JbegsD8LG6tEifG7hYm4vt6klrM3XUYD4c /OF/VQrx5k26BaKpOZDu06z8WrwjSjLYcRWbYlw5jl+OQdD6p4Qg7UfuRjTyq2YsGo8Z b+nYOhzrTi0uOZ3SXPGNYT9A80DvAtHV7UGIpXfQ5TWQJ1ce1fMJpxPkhJuLV/qnXLbh ycQwakLS72kUlsMd4z0+Par3S+deSU3ewjg0Asa37BAjMp/jbTEATKeUoB/2ITiP2Ehy 7MeC+/b06efM15F+pMKMZY197ibcRKw9Wa9hFtyh7wNt6+nniLWSmq+AXke5XuZ+YFE3 YRFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjMKFIBr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t10-20020a63460a000000b003816043f063si3047716pga.600.2022.03.25.11.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:51:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjMKFIBr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84D961B3091; Fri, 25 Mar 2022 11:03:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378586AbiCYPfK (ORCPT + 99 others); Fri, 25 Mar 2022 11:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377823AbiCYPYh (ORCPT ); Fri, 25 Mar 2022 11:24:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEBB9EA369; Fri, 25 Mar 2022 08:19:01 -0700 (PDT) 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 3E0D860EFC; Fri, 25 Mar 2022 15:19:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48390C340EE; Fri, 25 Mar 2022 15:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1648221540; bh=SnuKPbhnso54nZZOxdM0e1yQi96s8bbLXt1EdmvRqBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjMKFIBr95/r7AN/xc16085l1cuMub1bvmfkvz76PQTNywHWMdKP7RVk5mol5eNR5 LN/1RSS+91DW9EVdErt264X/pz9h80Gn+45MLnW/MKKWyrEvGE0TG9fqCNMYjdmAOc SL4dUTUcF5LONu9hW/6VRotajDNMCOjEQ+Z1cjIA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso Subject: [PATCH 5.17 21/39] netfilter: nf_tables: validate registers coming from userspace. Date: Fri, 25 Mar 2022 16:14:36 +0100 Message-Id: <20220325150420.849930245@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220325150420.245733653@linuxfoundation.org> References: <20220325150420.245733653@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso commit 6e1acfa387b9ff82cfc7db8cc3b6959221a95851 upstream. Bail out in case userspace uses unsupported registers. Fixes: 49499c3e6e18 ("netfilter: nf_tables: switch registers to 32 bit addressing") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -9275,17 +9275,23 @@ int nft_parse_u32_check(const struct nla } EXPORT_SYMBOL_GPL(nft_parse_u32_check); -static unsigned int nft_parse_register(const struct nlattr *attr) +static unsigned int nft_parse_register(const struct nlattr *attr, u32 *preg) { unsigned int reg; reg = ntohl(nla_get_be32(attr)); switch (reg) { case NFT_REG_VERDICT...NFT_REG_4: - return reg * NFT_REG_SIZE / NFT_REG32_SIZE; + *preg = reg * NFT_REG_SIZE / NFT_REG32_SIZE; + break; + case NFT_REG32_00...NFT_REG32_15: + *preg = reg + NFT_REG_SIZE / NFT_REG32_SIZE - NFT_REG32_00; + break; default: - return reg + NFT_REG_SIZE / NFT_REG32_SIZE - NFT_REG32_00; + return -ERANGE; } + + return 0; } /** @@ -9327,7 +9333,10 @@ int nft_parse_register_load(const struct u32 reg; int err; - reg = nft_parse_register(attr); + err = nft_parse_register(attr, ®); + if (err < 0) + return err; + err = nft_validate_register_load(reg, len); if (err < 0) return err; @@ -9382,7 +9391,10 @@ int nft_parse_register_store(const struc int err; u32 reg; - reg = nft_parse_register(attr); + err = nft_parse_register(attr, ®); + if (err < 0) + return err; + err = nft_validate_register_store(ctx, reg, data, type, len); if (err < 0) return err;