Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3080733pxj; Mon, 17 May 2021 17:16:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhY4betDNk1fc85zPVtZnPetjAQSgVwKVTIhnFdoCMLMBuk+lYgBVXKyPpJozcZqDM2BC5 X-Received: by 2002:a17:906:2546:: with SMTP id j6mr2820819ejb.51.1621296999696; Mon, 17 May 2021 17:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621296999; cv=none; d=google.com; s=arc-20160816; b=wvs1lLXzptYANbkMTOUB0l41Yhb+6rmrSH0xUnp8ZJvZle5t5AYgwrEiwj9A9gXaVe nuhuvBbCeY63dYpDkRFvL8UYH5iTgE6EvvLfbsIzE1wX9i5CLm+nQnL561jQDrIZC/Cw 7xghmTDpB7vfvOjcv1GTX8QONwR9dUDNlKspiCQQhU9ZEtA7HQxY9pyqy2lA2Ia9BRxg Tny3/u1qpvoCNJkIGWMcetFWUdh1U5NVKvHBMj45puQBkX0PFScdEF+P/r6lQO4yMGSb DMPs08ZEEaa1GhDv22ywqc4WpYbdvuA7XVdt7bdfQQdo7KXSomNL5I4mk77mgHKEDIwz rshg== 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=OA4kez6xsnwW0QK6H1JCjId5UNk/nJ3hG/XMmzPgDFo=; b=zrMa52hAgpC6wBg4T5mP/FdreVA8oKdfapGBeKIhBGRA2cjeHZqHvoIi3sn3yQxww6 J+0QvIa4HjiPo07hjwvsnSaZ06PPW2EFNr6cmDZ3gDkXuiHsgQJwM6d67TF9NpnT5zOp xLIgMT6R84I7pg2oQ1g7pTOI4NePiC7pETVC0rI4Vji4dpggbhg+FU4VtMnvdcifnd6T zo4M77eWvaMYvfpl344HvyifxtALN1YMOmziv0EoyfdxfJ+WOw8wK4Vw3CUexTgE5ASu Y6I9FnC9e71ZQPEejEGw8kNRHc3plpxaCSTf0G+ZEM6QevVakdeEfZQb+n5P567/X3DP /yNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rZ/l1N4X"; 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 ay17si17847176ejb.736.2021.05.17.17.16.00; Mon, 17 May 2021 17:16:39 -0700 (PDT) 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="rZ/l1N4X"; 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 S239346AbhEQO0K (ORCPT + 99 others); Mon, 17 May 2021 10:26:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:36022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239229AbhEQOW2 (ORCPT ); Mon, 17 May 2021 10:22:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 12348613BD; Mon, 17 May 2021 14:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260721; bh=3Znwa8eS3gANP3LDethwCADKAU72WDg9Fnlgs0Owfa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZ/l1N4XKJuNA3XJLpyHUorGPxo9c/CfZURgriikVi1/8JIVLXwlXptI31jpGp156 JO8FLnhLvrLvK0pBjWl2QNjT9OfNgR1HAjdSbXpn9/w4UqqV56lOCWolN2vzb3WMGt oJlQWPvbM3S7k5JYAoqHmU3so3oyPDSEq/pJMVq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Sutter , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.12 209/363] netfilter: xt_SECMARK: add new revision to fix structure layout Date: Mon, 17 May 2021 16:01:15 +0200 Message-Id: <20210517140309.651244494@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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: Pablo Neira Ayuso [ Upstream commit c7d13358b6a2f49f81a34aa323a2d0878a0532a2 ] This extension breaks when trying to delete rules, add a new revision to fix this. Fixes: 5e6874cdb8de ("[SECMARK]: Add xtables SECMARK target") Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- include/uapi/linux/netfilter/xt_SECMARK.h | 6 ++ net/netfilter/xt_SECMARK.c | 88 ++++++++++++++++++----- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/include/uapi/linux/netfilter/xt_SECMARK.h b/include/uapi/linux/netfilter/xt_SECMARK.h index 1f2a708413f5..beb2cadba8a9 100644 --- a/include/uapi/linux/netfilter/xt_SECMARK.h +++ b/include/uapi/linux/netfilter/xt_SECMARK.h @@ -20,4 +20,10 @@ struct xt_secmark_target_info { char secctx[SECMARK_SECCTX_MAX]; }; +struct xt_secmark_target_info_v1 { + __u8 mode; + char secctx[SECMARK_SECCTX_MAX]; + __u32 secid; +}; + #endif /*_XT_SECMARK_H_target */ diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index 75625d13e976..498a0bf6f044 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -24,10 +24,9 @@ MODULE_ALIAS("ip6t_SECMARK"); static u8 mode; static unsigned int -secmark_tg(struct sk_buff *skb, const struct xt_action_param *par) +secmark_tg(struct sk_buff *skb, const struct xt_secmark_target_info_v1 *info) { u32 secmark = 0; - const struct xt_secmark_target_info *info = par->targinfo; switch (mode) { case SECMARK_MODE_SEL: @@ -41,7 +40,7 @@ secmark_tg(struct sk_buff *skb, const struct xt_action_param *par) return XT_CONTINUE; } -static int checkentry_lsm(struct xt_secmark_target_info *info) +static int checkentry_lsm(struct xt_secmark_target_info_v1 *info) { int err; @@ -73,15 +72,15 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) return 0; } -static int secmark_tg_check(const struct xt_tgchk_param *par) +static int +secmark_tg_check(const char *table, struct xt_secmark_target_info_v1 *info) { - struct xt_secmark_target_info *info = par->targinfo; int err; - if (strcmp(par->table, "mangle") != 0 && - strcmp(par->table, "security") != 0) { + if (strcmp(table, "mangle") != 0 && + strcmp(table, "security") != 0) { pr_info_ratelimited("only valid in \'mangle\' or \'security\' table, not \'%s\'\n", - par->table); + table); return -EINVAL; } @@ -116,25 +115,76 @@ static void secmark_tg_destroy(const struct xt_tgdtor_param *par) } } -static struct xt_target secmark_tg_reg __read_mostly = { - .name = "SECMARK", - .revision = 0, - .family = NFPROTO_UNSPEC, - .checkentry = secmark_tg_check, - .destroy = secmark_tg_destroy, - .target = secmark_tg, - .targetsize = sizeof(struct xt_secmark_target_info), - .me = THIS_MODULE, +static int secmark_tg_check_v0(const struct xt_tgchk_param *par) +{ + struct xt_secmark_target_info *info = par->targinfo; + struct xt_secmark_target_info_v1 newinfo = { + .mode = info->mode, + }; + int ret; + + memcpy(newinfo.secctx, info->secctx, SECMARK_SECCTX_MAX); + + ret = secmark_tg_check(par->table, &newinfo); + info->secid = newinfo.secid; + + return ret; +} + +static unsigned int +secmark_tg_v0(struct sk_buff *skb, const struct xt_action_param *par) +{ + const struct xt_secmark_target_info *info = par->targinfo; + struct xt_secmark_target_info_v1 newinfo = { + .secid = info->secid, + }; + + return secmark_tg(skb, &newinfo); +} + +static int secmark_tg_check_v1(const struct xt_tgchk_param *par) +{ + return secmark_tg_check(par->table, par->targinfo); +} + +static unsigned int +secmark_tg_v1(struct sk_buff *skb, const struct xt_action_param *par) +{ + return secmark_tg(skb, par->targinfo); +} + +static struct xt_target secmark_tg_reg[] __read_mostly = { + { + .name = "SECMARK", + .revision = 0, + .family = NFPROTO_UNSPEC, + .checkentry = secmark_tg_check_v0, + .destroy = secmark_tg_destroy, + .target = secmark_tg_v0, + .targetsize = sizeof(struct xt_secmark_target_info), + .me = THIS_MODULE, + }, + { + .name = "SECMARK", + .revision = 1, + .family = NFPROTO_UNSPEC, + .checkentry = secmark_tg_check_v1, + .destroy = secmark_tg_destroy, + .target = secmark_tg_v1, + .targetsize = sizeof(struct xt_secmark_target_info_v1), + .usersize = offsetof(struct xt_secmark_target_info_v1, secid), + .me = THIS_MODULE, + }, }; static int __init secmark_tg_init(void) { - return xt_register_target(&secmark_tg_reg); + return xt_register_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg)); } static void __exit secmark_tg_exit(void) { - xt_unregister_target(&secmark_tg_reg); + xt_unregister_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg)); } module_init(secmark_tg_init); -- 2.30.2