From: Kees Cook <keescook@chromium.org>
To: Miguel Ojeda <ojeda@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
Changbin Du <changbin.du@intel.com>,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <nathan@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Boqun Feng <boqun.feng@gmail.com>
Subject: Re: [PATCH v1 1/3] kallsyms: avoid hardcoding the buffer size
Date: Thu, 5 May 2022 16:46:33 -0700 [thread overview]
Message-ID: <202205051643.1A8E38C7F2@keescook> (raw)
In-Reply-To: <20220505191704.22812-2-ojeda@kernel.org>
On Thu, May 05, 2022 at 09:16:43PM +0200, Miguel Ojeda wrote:
> From: Boqun Feng <boqun.feng@gmail.com>
>
> This makes it easier to update the size later on.
>
> Furthermore, a static assert is added to ensure both are updated
> when that happens. The relationship used is one that keeps the new
> size (512+1) close to the original buffer size (500).
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> scripts/kallsyms.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
> index 8caabddf817c..880c4404731b 100644
> --- a/scripts/kallsyms.c
> +++ b/scripts/kallsyms.c
> @@ -27,8 +27,18 @@
>
> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
>
> +#define _stringify_1(x) #x
> +#define _stringify(x) _stringify_1(x)
> +
> #define KSYM_NAME_LEN 128
>
> +/* A substantially bigger size than the current maximum. */
> +#define KSYM_NAME_LEN_BUFFER 512
> +_Static_assert(
> + KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4,
> + "Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN"
> +);
> +
> struct sym_entry {
> unsigned long long addr;
> unsigned int len;
> @@ -197,15 +207,15 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
>
> static struct sym_entry *read_symbol(FILE *in)
> {
> - char name[500], type;
> + char name[KSYM_NAME_LEN_BUFFER+1], type;
> unsigned long long addr;
> unsigned int len;
> struct sym_entry *sym;
> int rc;
>
> - rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name);
> + rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name);
> if (rc != 3) {
> - if (rc != EOF && fgets(name, 500, in) == NULL)
> + if (rc != EOF && fgets(name, KSYM_NAME_LEN_BUFFER + 1, in) == NULL)
No need to repeat the sizing:
fgets(name, sizeof(name), in)
> fprintf(stderr, "Read error or end of file.\n");
> return NULL;
> }
> --
> 2.35.3
>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
next prev parent reply other threads:[~2022-05-05 23:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 19:16 [PATCH v1 0/3] kallsyms: Rust requirements Miguel Ojeda
2022-05-05 19:16 ` [PATCH v1 1/3] kallsyms: avoid hardcoding the buffer size Miguel Ojeda
2022-05-05 23:46 ` Kees Cook [this message]
2022-05-06 5:26 ` Miguel Ojeda
2022-05-06 11:19 ` James Bottomley
2022-05-06 12:58 ` Miguel Ojeda
2022-05-06 14:48 ` James Bottomley
2022-05-05 19:16 ` [PATCH v1 2/3] kallsyms: support "big" kernel symbols Miguel Ojeda
2022-05-05 23:47 ` Kees Cook
2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
2022-05-05 23:48 ` Kees Cook
2022-05-06 8:34 ` Petr Mladek
2022-05-06 9:45 ` Geert Stappers
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=202205051643.1A8E38C7F2@keescook \
--to=keescook@chromium.org \
--cc=boqun.feng@gmail.com \
--cc=changbin.du@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.