Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp39563pja; Fri, 22 Nov 2019 03:10:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzcHavG7mxglP33EipZb5EglNtlTDtakNS9xOhsIK6+FZuA0O8Dbe+fAAXXLvqLJsrEH2HI X-Received: by 2002:a50:a7a1:: with SMTP id i30mr341900edc.94.1574421023831; Fri, 22 Nov 2019 03:10:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421023; cv=none; d=google.com; s=arc-20160816; b=nGNI4DO7lw190fC82FyPyk/9/2/o7qRZzYJ5YGPdJLGWUdhIPnh51mTjcwL5vMDSFr 4KVTY+sjwDEDon1q0xA2uPjZ0jpgMla+MfnT5Vpnw3auqDyYuPppWn2qLGia9bGDN55O QxEEhnai/88IrB5Zj+pa/xZch+FQppyuNhS5YJNWjSUKfF9UvE6nQo+vlzKuRu8ZL/gT 16sFUFKWAvm7lZgSonFIGrBzyCRrEST3iWEhj0lHYdWQK+qi0NhesxtW9egcviq7nfrh MYM16ueyI17hhjQ7l4VRbxw48/UY1rMFFSTPnv5x+cSGIh4hSongeVdMnkS9soCubxV4 gP2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XHACLrJAwp1+A/G6BvfGFPxpmmkJZ/G2ZFruUaHY7y4=; b=TvhW3+Zh1bvynF79njhM/q4oWRweOKYvwAIzsDS2tGUxT5rMQIQbdHUvTX2GWKCvhR S9HQ3JrNBgzTTDAbyDZsZjXCqhAMUxs/NRBUrWcjmL2Oe9VfknRZHmoUla6HzBhN27nt +Hs+TrUHlmCyOCpFDlVgM5+TnU2H/yFa2PgXX/3dv3JuihNE7RdHJ4gA0O2YprubnSGc TKeEzPivZi/5pVTRVDdi9jPSJTW0v2BZao5KGA+JqKVH3MchuIXN5Ko/nxJu52hXkfb/ O37SEQ8nEhBa2rf+3AbsK3OrHxiS8gpCfKnTmfOmFkqcqywaB5fl9y8RxKZwNgDZtfTj Ut5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljMJI6FU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si4154487edv.423.2019.11.22.03.09.59; Fri, 22 Nov 2019 03:10:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljMJI6FU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731732AbfKVLFg (ORCPT + 99 others); Fri, 22 Nov 2019 06:05:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:33116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730755AbfKVLFd (ORCPT ); Fri, 22 Nov 2019 06:05:33 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2FA172075E; Fri, 22 Nov 2019 11:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574420732; bh=Sdmu46wqyOZ8xb4qgKmubdm8/s9CbLdUeDfQxVPweYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljMJI6FUEFvqyHwj7pQNanZwR9bicERvdNOyjpPyI2z8VakDcA38q68AOxv/uKd6z OzsAPXV/WIc/uIUat3rp3G5Knr4EGNmSJpt5nfzddtHmfZ5IjF7/KuzFw7mZHlBlpB AK2Dop1Elvk2tIBBiSnpqOBUzDqq3KnxmYH3NSsQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.19 206/220] netfilter: nft_compat: do not dump private area Date: Fri, 22 Nov 2019 11:29:31 +0100 Message-Id: <20191122100928.615120804@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100912.732983531@linuxfoundation.org> References: <20191122100912.732983531@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit d701d8117200399d85e63a737d2e4e897932f3b6 ] Zero pad private area, otherwise we expose private kernel pointer to userspace. This patch also zeroes the tail area after the ->matchsize and ->targetsize that results from XT_ALIGN(). Fixes: 0ca743a55991 ("netfilter: nf_tables: add compatibility layer for x_tables") Reported-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_compat.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c index 1245e02239d90..469f9da5073bf 100644 --- a/net/netfilter/nft_compat.c +++ b/net/netfilter/nft_compat.c @@ -269,6 +269,24 @@ nft_target_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) kfree(expr->ops); } +static int nft_extension_dump_info(struct sk_buff *skb, int attr, + const void *info, + unsigned int size, unsigned int user_size) +{ + unsigned int info_size, aligned_size = XT_ALIGN(size); + struct nlattr *nla; + + nla = nla_reserve(skb, attr, aligned_size); + if (!nla) + return -1; + + info_size = user_size ? : size; + memcpy(nla_data(nla), info, info_size); + memset(nla_data(nla) + info_size, 0, aligned_size - info_size); + + return 0; +} + static int nft_target_dump(struct sk_buff *skb, const struct nft_expr *expr) { const struct xt_target *target = expr->ops->data; @@ -276,7 +294,8 @@ static int nft_target_dump(struct sk_buff *skb, const struct nft_expr *expr) if (nla_put_string(skb, NFTA_TARGET_NAME, target->name) || nla_put_be32(skb, NFTA_TARGET_REV, htonl(target->revision)) || - nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(target->targetsize), info)) + nft_extension_dump_info(skb, NFTA_TARGET_INFO, info, + target->targetsize, target->usersize)) goto nla_put_failure; return 0; @@ -504,7 +523,8 @@ static int __nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr, if (nla_put_string(skb, NFTA_MATCH_NAME, match->name) || nla_put_be32(skb, NFTA_MATCH_REV, htonl(match->revision)) || - nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(match->matchsize), info)) + nft_extension_dump_info(skb, NFTA_MATCH_INFO, info, + match->matchsize, match->usersize)) goto nla_put_failure; return 0; -- 2.20.1