Linux Test Project
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH 1/3] lib: Avoid loop_info.lo_name buffer overflow
Date: Fri, 17 Jul 2026 14:33:18 +0200	[thread overview]
Message-ID: <20260717-fix_core_library-v1-1-c575fcbb2cb3@suse.com> (raw)
In-Reply-To: <20260717-fix_core_library-v1-0-c575fcbb2cb3@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

The backing file path may be longer than the fixed-size lo_name field,
so an unbounded strcpy() can overflow the loop_info structure. Copy at
most the field size and rely on the preceding memset() for termination.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 lib/tst_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tst_device.c b/lib/tst_device.c
index d3c53a1a18d2e4948ebff21d6d66c0ccd1590c6f..b5c3ccdb7be52ce600fbd7d7a83f6081df65d616 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -182,7 +182,7 @@ int tst_attach_device(const char *dev, const char *file)
 	 * LOOP_SET_FD and LOOP_SET_STATUS.
 	 */
 	memset(&loopinfo, 0, sizeof(loopinfo));
-	strcpy(loopinfo.lo_name, file);
+	strncpy(loopinfo.lo_name, file, sizeof(loopinfo.lo_name) - 1);
 
 	if (ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo)) {
 		close(dev_fd);

-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-07-17 12:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 12:33 [LTP] [PATCH 0/3] Fix bugs in LTP core library Andrea Cervesato
2026-07-17 12:33 ` Andrea Cervesato [this message]
2026-07-17 13:33   ` [LTP] lib: Avoid loop_info.lo_name buffer overflow linuxtestproject.agent
2026-07-28 13:58   ` [LTP] [PATCH 1/3] " Petr Vorel
2026-07-28 14:19     ` Andrea Cervesato via ltp
2026-07-28 21:02       ` Petr Vorel
2026-07-17 12:33 ` [LTP] [PATCH 2/3] lib: Close directory fd on ENOSPC in tst_fill_fs Andrea Cervesato
2026-07-28 14:00   ` Petr Vorel
2026-07-17 12:33 ` [LTP] [PATCH 3/3] lib: Fix wrong field in tst_iovec_alloc Andrea Cervesato
2026-07-28 14:02   ` Petr Vorel

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=20260717-fix_core_library-v1-1-c575fcbb2cb3@suse.com \
    --to=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /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