linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: linux-modules@vger.kernel.org
Subject: [PATCH] Fix segmentation fault on empty signature key
Date: Sun, 15 Feb 2015 00:34:53 +0100	[thread overview]
Message-ID: <20150214233452.GA7778@localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]

Hi,

a segmentation fault occurs if a module has an empty key attached to
its signature.

This happens because it's assumed that at least one key byte is
available, subtracting it in libkmod-module line 2249.  This -1 value
is casted to an unsigned data type later on, resulting in illegal
memory access.

Attached please find a proof of concept module, tested on amd64:

tobias:~$ modinfo 0sig.ko
filename:       /home/tobias/0sig.ko
Segmentation fault

Tobias
---
 libkmod/libkmod-module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 30f15ca..ca703a7 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -2246,7 +2246,8 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
 				key_hex[i * 3 + 2] = ':';
 		}
 		n = kmod_module_info_append(list, "sig_key", strlen("sig_key"),
-				key_hex, sig_info.key_id_len * 3 - 1);
+				key_hex, sig_info.key_id_len == 0 ? 0 :
+				sig_info.key_id_len * 3 - 1);
 		free(key_hex);
 		if (n == NULL)
 			goto list_error;
-- 
2.3.0


[-- Attachment #2: 0sig.ko --]
[-- Type: application/octet-stream, Size: 336 bytes --]

             reply	other threads:[~2015-02-14 23:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-14 23:34 Tobias Stoeckmann [this message]
2015-02-15 11:46 ` [PATCH] Fix segmentation fault on empty signature key Lucas De Marchi
2015-02-18 18:22 ` 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=20150214233452.GA7778@localhost \
    --to=tobias@stoeckmann.org \
    --cc=linux-modules@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 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).