From: "Maciej Żenczykowski" <zenczykowski@gmail.com>
To: "Maciej Żenczykowski" <maze@google.com>,
"Pablo Neira Ayuso" <pablo@netfilter.org>,
"Florian Westphal" <fw@strlen.de>
Cc: Linux Network Development Mailing List <netdev@vger.kernel.org>,
Netfilter Development Mailing List
<netfilter-devel@vger.kernel.org>,
Manoj Basapathi <manojbm@codeaurora.org>,
Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Subject: [PATCH netfilter] netfilter: xt_IDLETIMER: fix idletimer_tg_helper non-kosher casts
Date: Fri, 2 Apr 2021 13:11:56 -0700 [thread overview]
Message-ID: <20210402201156.2789453-1-zenczykowski@gmail.com> (raw)
From: Maciej Żenczykowski <maze@google.com>
The code is relying on the identical layout of the beginning
of the v0 and v1 structs, but this can easily lead to code bugs
if one were to try to extend this further...
I use:
char (*plabel)[MAX_IDLETIMER_LABEL_SIZE]
instead of:
char label[MAX_IDLETIMER_LABEL_SIZE]
as the helper's argument to get better type safety
(the former checks array size, the latter does not).
Cc: Manoj Basapathi <manojbm@codeaurora.org>
Cc: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
net/netfilter/xt_IDLETIMER.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c
index 7b2f359bfce4..2b5e81f6e0bd 100644
--- a/net/netfilter/xt_IDLETIMER.c
+++ b/net/netfilter/xt_IDLETIMER.c
@@ -283,18 +283,19 @@ static unsigned int idletimer_tg_target_v1(struct sk_buff *skb,
return XT_CONTINUE;
}
-static int idletimer_tg_helper(struct idletimer_tg_info *info)
+static int idletimer_tg_helper(__u32 timeout,
+ char (*plabel)[MAX_IDLETIMER_LABEL_SIZE])
{
- if (info->timeout == 0) {
+ if (timeout == 0) {
pr_debug("timeout value is zero\n");
return -EINVAL;
}
- if (info->timeout >= INT_MAX / 1000) {
+ if (timeout >= INT_MAX / 1000) {
pr_debug("timeout value is too big\n");
return -EINVAL;
}
- if (info->label[0] == '\0' ||
- strnlen(info->label,
+ if ((*plabel)[0] == '\0' ||
+ strnlen(*plabel,
MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) {
pr_debug("label is empty or not nul-terminated\n");
return -EINVAL;
@@ -310,9 +311,8 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
pr_debug("checkentry targinfo%s\n", info->label);
- ret = idletimer_tg_helper(info);
- if(ret < 0)
- {
+ ret = idletimer_tg_helper(info->timeout, &info->label);
+ if (ret < 0) {
pr_debug("checkentry helper return invalid\n");
return -EINVAL;
}
@@ -349,9 +349,8 @@ static int idletimer_tg_checkentry_v1(const struct xt_tgchk_param *par)
if (info->send_nl_msg)
return -EOPNOTSUPP;
- ret = idletimer_tg_helper((struct idletimer_tg_info *)info);
- if(ret < 0)
- {
+ ret = idletimer_tg_helper(info->timeout, &info->label);
+ if (ret < 0) {
pr_debug("checkentry helper return invalid\n");
return -EINVAL;
}
--
2.31.0.208.g409f899ff0-goog
next reply other threads:[~2021-04-02 20:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-02 20:11 Maciej Żenczykowski [this message]
2021-04-02 21:40 ` [PATCH netfilter] netfilter: xt_IDLETIMER: fix idletimer_tg_helper non-kosher casts Florian Westphal
2021-04-02 22:50 ` Maciej Żenczykowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210402201156.2789453-1-zenczykowski@gmail.com \
--to=zenczykowski@gmail.com \
--cc=fw@strlen.de \
--cc=manojbm@codeaurora.org \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=subashab@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).