lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20231116191452.work.902-kees@kernel.org>
Date: Thu, 16 Nov 2023 11:14:52 -0800
From: Kees Cook <keescook@...omium.org>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Kees Cook <keescook@...omium.org>,
	Will McVicker <willmcvicker@...gle.com>,
	"Gustavo A. R. Silva" <gustavoars@...nel.org>,
	Peter Chen <peter.chen@....com>,
	Davidlohr Bueso <dave@...olabs.net>,
	Zhang Qilong <zhangqilong3@...wei.com>,
	Linyu Yuan <quic_linyyuan@...cinc.com>,
	John Keeping <john@...ping.me.uk>,
	Azeem Shaikh <azeemshaikh38@...il.com>,
	linux-usb@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org
Subject: [PATCH] usb: gadget: f_midi: Replace strlcpy() with strscpy()

strlcpy() reads the entire source buffer first. This read may exceed
the destination size limit. This is both inefficient and can lead
to linear read overflows if a source string is not NUL-terminated[1].
Additionally, it returns the size of the source string, not the
resulting size of the destination string. In an effort to remove strlcpy()
completely[2], replace strlcpy() here with strscpy().

In the unlikely (impossible?) case where opts->id was larger than
PAGE_SIZE, this will now correctly report truncation errors.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1]
Link: https://github.com/KSPP/linux/issues/89 [2]
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Will McVicker <willmcvicker@...gle.com>
Cc: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Peter Chen <peter.chen@....com>
Cc: Davidlohr Bueso <dave@...olabs.net>
Cc: Zhang Qilong <zhangqilong3@...wei.com>
Cc: Linyu Yuan <quic_linyyuan@...cinc.com>
Cc: John Keeping <john@...ping.me.uk>
Cc: Azeem Shaikh <azeemshaikh38@...il.com>
Cc: linux-usb@...r.kernel.org
Signed-off-by: Kees Cook <keescook@...omium.org>
---
 drivers/usb/gadget/function/f_midi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index 5335845d697b..20c6fbd94f32 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -1177,11 +1177,11 @@ F_MIDI_OPT(out_ports, true, MAX_PORTS);
 static ssize_t f_midi_opts_id_show(struct config_item *item, char *page)
 {
 	struct f_midi_opts *opts = to_f_midi_opts(item);
-	int result;
+	ssize_t result;
 
 	mutex_lock(&opts->lock);
 	if (opts->id) {
-		result = strlcpy(page, opts->id, PAGE_SIZE);
+		result = strscpy(page, opts->id, PAGE_SIZE);
 	} else {
 		page[0] = 0;
 		result = 0;
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ