Skip to content

Commit 1fb64bf

Browse files
author
Steve French
committed
[CIFS] when mount helper missing fix slash wrong direction in share
Kernel bugzilla bug #9228 If mount helper (mount.cifs) missing, mounts with form like //10.11.12.13/c$ would not work (only mounts with slash e.g. //10.11.12.13\\c$ would work) due to problem with slash supposed to be converted to backslash by the mount helper (which is not there). If we fail on converting an IPv4 address in in4_pton then try to canonicalize the first slash (ie between sharename and host ip address) if necessary. If we have to retry to check for IPv6 address the slash is already converted if necessary. Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent 953f868 commit 1fb64bf

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎fs/cifs/CHANGES‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ bigendian architectures. Fix possible memory corruption when
1414
EAGAIN returned on kern_recvmsg. Return better error if server
1515
requires packet signing but client has disabled it. When mounted
1616
with cifsacl mount option - mode bits are approximated based
17-
on the contents of the files ACL.
17+
on the contents of the ACL of the file or directory. When cifs
18+
mount helper is missing convert make sure that UNC name
19+
has backslash (not forward slash) between ip address of server
20+
and the share name.
1821

1922
Version 1.50
2023
------------

‎fs/cifs/netmisc.c‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
132132
{0, 0}
133133
};
134134

135+
136+
/* if the mount helper is missing we need to reverse the 1st slash
137+
from '/' to backslash in order to format the UNC properly for
138+
ip address parsing and for tree connect (unless the user
139+
remembered to put the UNC name in properly). Fortunately we do
140+
not have to call this twice (we check for IPv4 addresses
141+
first, so it is already converted by the time we
142+
try IPv6 addresses */
143+
static int canonicalize_unc(char *cp)
144+
{
145+
int i;
146+
147+
for (i = 0; i <= 46 /* INET6_ADDRSTRLEN */ ; i++) {
148+
if (cp[i] == 0)
149+
break;
150+
if (cp[i] == '\\')
151+
break;
152+
if (cp[i] == '/') {
153+
#ifdef CONFIG_CIFS_DEBUG2
154+
cFYI(1, ("change slash to backslash in malformed UNC"));
155+
#endif
156+
cp[i] = '\\';
157+
return 1;
158+
}
159+
}
160+
return 0;
161+
}
162+
135163
/* Convert string containing dotted ip address to binary form */
136164
/* returns 0 if invalid address */
137165

@@ -141,11 +169,13 @@ cifs_inet_pton(int address_family, char *cp, void *dst)
141169
int ret = 0;
142170

143171
/* calculate length by finding first slash or NULL */
144-
/* BB Should we convert '/' slash to '\' here since it seems already
145-
* done before this */
146-
if ( address_family == AF_INET ) {
147-
ret = in4_pton(cp, -1 /* len */, dst , '\\', NULL);
148-
} else if ( address_family == AF_INET6 ) {
172+
if (address_family == AF_INET) {
173+
ret = in4_pton(cp, -1 /* len */, dst, '\\', NULL);
174+
if (ret == 0) {
175+
if (canonicalize_unc(cp))
176+
ret = in4_pton(cp, -1, dst, '\\', NULL);
177+
}
178+
} else if (address_family == AF_INET6) {
149179
ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL);
150180
}
151181
#ifdef CONFIG_CIFS_DEBUG2

0 commit comments

Comments
 (0)