Skip to content

Commit

Permalink
zmo->name needs to be NonPaged
Browse files Browse the repository at this point in the history
Due to IRP_MN_MOUNT_VOLUME being called at high irql, and
we copy name over to VolumeLabel.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Sep 4, 2024
1 parent 8c07c15 commit 5e7e013
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/os/windows/zfs/sys/zfs_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ extern int zfs_init_cache(FILE_OBJECT *fo, struct vnode *vp,

/* zfs_vnop_windows_lib.h */
extern int AsciiStringToUnicodeString(char *in, PUNICODE_STRING out);
extern int AsciiStringToUnicodeStringNP(char *in, PUNICODE_STRING out);
extern void FreeUnicodeString(PUNICODE_STRING s);
extern int zfs_vfs_uuid_gen(const char *osname, uuid_t uuid);
extern int zfs_vfs_uuid_unparse(uuid_t uuid, char *dst);
Expand Down
39 changes: 39 additions & 0 deletions module/os/windows/zfs/zfs_vnops_windows_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,45 @@ AsciiStringToUnicodeString(char *in, PUNICODE_STRING out)
return (RtlAnsiStringToUnicodeString(out, &conv, TRUE));
}

/*
* Same again, but use NonPaged memory.
* IRP_MN_MOUNT_VOLUME is called with irql==2, and
* we try to copy zmo->name.Buffer to VolumeLabel, which
* is not allowed.
*/
int
AsciiStringToUnicodeStringNP(char *in, PUNICODE_STRING out)
{
NTSTATUS status;
ULONG len;

memset(out, 0, sizeof (UNICODE_STRING));
if (in == NULL)
return (0);

status = RtlUTF8ToUnicodeN(NULL, 0, &len,
in, strlen(in));
if (!NT_SUCCESS(status))
return (0);

out->Buffer = (PWSTR)ExAllocatePoolWithTag(NonPagedPoolNx,
len + sizeof (WCHAR), 'tag1');

if (out->Buffer == NULL)
return (0);

out->Length = len;
out->MaximumLength = len + sizeof (WCHAR);

status = RtlUTF8ToUnicodeN(out->Buffer, out->MaximumLength,
NULL,
in, strlen(in));

out->Buffer[out->Length / sizeof (WCHAR)] =
UNICODE_NULL;
return (0);
}

void
FreeUnicodeString(PUNICODE_STRING s)
{
Expand Down
2 changes: 1 addition & 1 deletion module/os/windows/zfs/zfs_vnops_windows_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ zfs_windows_mount(zfs_cmd_t *zc)
// Should we keep the name with slashes like "BOOM/lower" or
// just "lower". Turns out the name in Explorer only
// works for 4 chars or lower. Why?
AsciiStringToUnicodeString(zc->zc_name, &zmo_dcb->name);
AsciiStringToUnicodeStringNP(zc->zc_name, &zmo_dcb->name);
RtlDuplicateUnicodeString(0, &diskDeviceName, &zmo_dcb->device_name);

// strlcpy(zc->zc_value, buf, sizeof (zc->zc_value));
Expand Down

0 comments on commit 5e7e013

Please sign in to comment.