Skip to content

Commit db343d8

Browse files
mdouchapevik
authored andcommitted
ioctl_sg01: Allow using USB device again
The failures when the ioctl_sg01 test tried to query a USB device turned out to be another data leak. Allow using USB devices again but keep the improved device lookup algorithm. Link: https://lore.kernel.org/ltp/20260122171249.31590-1-mdoucha@suse.cz/ Reviewed-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Petr Vorel <pvorel@suse.cz> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
1 parent c47ab95 commit db343d8

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

testcases/kernel/syscalls/ioctl/ioctl_sg01.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "tst_memutils.h"
3131

3232
#define SYSDIR "/sys/block"
33-
#define BLOCKDIR "/sys/block/%s/device"
33+
#define BLOCKDIR "/sys/block/%s/device/generic"
3434

3535
#define BUF_SIZE (128 * 4096)
3636
#define CMD_SIZE 6
@@ -41,14 +41,14 @@ static unsigned char command[CMD_SIZE];
4141
static struct sg_io_hdr query;
4242

4343
/* TODO: split this off to a separate SCSI library? */
44-
static const char *find_generic_scsi_device(int access_flags, int skip_usb)
44+
static const char *find_generic_scsi_device(int access_flags)
4545
{
4646
DIR *sysdir;
4747
struct dirent *ent;
4848
int tmpfd;
4949
ssize_t length;
5050
char *filename;
51-
static char devpath[PATH_MAX], syspath[PATH_MAX];
51+
static char devpath[PATH_MAX], genpath[PATH_MAX];
5252

5353
sysdir = opendir(SYSDIR);
5454

@@ -60,28 +60,15 @@ static const char *find_generic_scsi_device(int access_flags, int skip_usb)
6060
if (ent->d_name[0] == '.')
6161
continue;
6262

63-
snprintf(syspath, PATH_MAX, BLOCKDIR, ent->d_name);
64-
syspath[PATH_MAX - 1] = '\0';
65-
66-
/* Real device path matches the physical HW bus path */
67-
if (!realpath(syspath, devpath))
68-
continue;
69-
70-
strncat(devpath, "/generic", PATH_MAX - strlen(devpath) - 1);
63+
snprintf(devpath, PATH_MAX, BLOCKDIR, ent->d_name);
7164
devpath[PATH_MAX - 1] = '\0';
72-
length = readlink(devpath, syspath, PATH_MAX - 1);
65+
length = readlink(devpath, genpath, PATH_MAX - 1);
7366

7467
if (length < 0)
7568
continue;
7669

77-
syspath[length] = '\0';
78-
filename = basename(syspath);
79-
80-
/* USB devices often return HW info in SG_IO response buffer */
81-
if (skip_usb && strstr(devpath, "/usb")) {
82-
tst_res(TINFO, "Skipping USB device %s", filename);
83-
continue;
84-
}
70+
genpath[length] = '\0';
71+
filename = basename(genpath);
8572

8673
snprintf(devpath, PATH_MAX, "/dev/%s", filename);
8774
/* access() makes incorrect assumptions about block devices */
@@ -121,7 +108,7 @@ static void dump_hex(const char *str, size_t size)
121108

122109
static void setup(void)
123110
{
124-
const char *devpath = find_generic_scsi_device(O_RDONLY, 1);
111+
const char *devpath = find_generic_scsi_device(O_RDONLY);
125112

126113
if (!devpath)
127114
tst_brk(TCONF, "Could not find any usable SCSI device");

0 commit comments

Comments
 (0)