linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: Yauheni Kaliuta <ykaliuta@redhat.com>
Cc: linux-modules@vger.kernel.org, lucas.de.marchi@gmail.com
Subject: Re: [PATCH 2/2] libkmod-builtin: consider final NIL in name length check
Date: Wed, 9 Jun 2021 10:18:49 -0700	[thread overview]
Message-ID: <20210609171849.xvbgrsvyehxueowd@ldmartin-desk2> (raw)
In-Reply-To: <20210609171053.c72kzwcdkdrgcwpv@ldmartin-desk2>

On Wed, Jun 09, 2021 at 10:10:53AM -0700, Lucas De Marchi wrote:
>On Tue, Jun 08, 2021 at 09:29:23AM +0300, Yauheni Kaliuta wrote:
>>There is potential buffer overrun in kmod_builtin_iter_get_modname()
>>for the name of length PATH_MAX. The required buffer size is
>>PATH_MAX, so `modname[len] = '\0'` with len == PATH_MAX will write
>>right beyond the buffer.
>
>this doesn't look correct. "with len == PATH_MAX" we will actually
>return an error.
>
>What indeed is happening is truncation: since we are not reserving 1
>char for NUL termination, we will truncate the name. If we update the
>commit message to state the right reasoning, then we can land this patch.
>
>I don't see any buffer overflow here, but I may be missing something.

another thing... what is your git-sendemail setup? This is putting patch
2 as a reply to patch 1 and that breaks b4. See:
https://lore.kernel.org/linux-modules/20210608062923.94017-1-ykaliuta@redhat.com/T/#u

Lucas De Marchi

>
>thanks
>LUcas De Marchi
>
>>
>>Check the length against PATH_MAX - 1.
>>
>>Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
>>---
>>libkmod/libkmod-builtin.c | 2 +-
>>1 file changed, 1 insertion(+), 1 deletion(-)
>>
>>diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c
>>index a002cb5ee2c6..3d4d77ab29b3 100644
>>--- a/libkmod/libkmod-builtin.c
>>+++ b/libkmod/libkmod-builtin.c
>>@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter,
>>
>>	len = dot - line;
>>
>>-	if (len >= PATH_MAX) {
>>+	if (len >= PATH_MAX - 1) {
>>		sv_errno = ENAMETOOLONG;
>>		goto fail;
>>	}
>>-- 
>>2.31.1
>>

  reply	other threads:[~2021-06-09 17:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  6:28 [PATCH 0/2] Fix a couple of potential problem (static analysis) Yauheni Kaliuta
2021-06-08  6:29 ` [PATCH 1/2] libkmod-module: check "new_from_name" return value in get_builtin Yauheni Kaliuta
2021-06-08  6:29   ` [PATCH 2/2] libkmod-builtin: consider final NIL in name length check Yauheni Kaliuta
2021-06-09 17:10     ` Lucas De Marchi
2021-06-09 17:18       ` Lucas De Marchi [this message]
2021-06-22  6:31         ` Yauheni Kaliuta
2021-06-22  6:22       ` Yauheni Kaliuta
2021-06-09 17:22   ` [PATCH 1/2] libkmod-module: check "new_from_name" return value in get_builtin Lucas De Marchi

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=20210609171849.xvbgrsvyehxueowd@ldmartin-desk2 \
    --to=lucas.demarchi@intel.com \
    --cc=linux-modules@vger.kernel.org \
    --cc=lucas.de.marchi@gmail.com \
    --cc=ykaliuta@redhat.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;
as well as URLs for NNTP newsgroup(s).