From: Len Baker <len.baker@gmx.com>
To: Vineet Gupta <vgupta@synopsys.com>
Cc: Len Baker <len.baker@gmx.com>,
"dean.yang_cp" <yangdianqing@yulong.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ARC: unwind: Use struct_size helper instead of open-coded arithmetic
Date: Fri, 16 Jul 2021 19:03:44 +0200 [thread overview]
Message-ID: <20210716170344.9150-1-len.baker@gmx.com> (raw)
Dynamic size calculations (especially multiplication) should not be
performed in memory allocator function arguments due to the risk of them
overflowing. This could lead to values wrapping around and a smaller
allocation being made than the caller was expecting. Using those
allocations could lead to linear overflows of heap memory and other
misbehaviors.
To avoid this scenario, use the struct_size helper.
Signed-off-by: Len Baker <len.baker@gmx.com>
---
arch/arc/kernel/unwind.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 47bab67f8649..af18052b86a7 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -13,6 +13,7 @@
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/memblock.h>
+#include <linux/overflow.h>
#include <linux/sort.h>
#include <linux/slab.h>
#include <linux/stop_machine.h>
@@ -312,9 +313,7 @@ static void init_unwind_hdr(struct unwind_table *table,
if (tableSize || !n)
goto ret_err;
- hdrSize = 4 + sizeof(unsigned long) + sizeof(unsigned int)
- + 2 * n * sizeof(unsigned long);
-
+ hdrSize = struct_size(header, table, n);
header = alloc(hdrSize);
if (!header)
goto ret_err;
--
2.25.1
next reply other threads:[~2021-07-16 17:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-16 17:03 Len Baker [this message]
2021-07-16 19:41 ` [PATCH] ARC: unwind: Use struct_size helper instead of open-coded arithmetic Gustavo A. R. Silva
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=20210716170344.9150-1-len.baker@gmx.com \
--to=len.baker@gmx.com \
--cc=gustavoars@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=vgupta@synopsys.com \
--cc=yangdianqing@yulong.com \
/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