diff options
Diffstat (limited to 'fs/cifs/dns_resolve.c')
| -rw-r--r-- | fs/cifs/dns_resolve.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c index 3ad7f4300c45..aa967e7917f8 100644 --- a/fs/cifs/dns_resolve.c +++ b/fs/cifs/dns_resolve.c | |||
| @@ -40,11 +40,11 @@ static const struct cred *dns_resolver_cache; | |||
| 40 | * 0 - name is not IP | 40 | * 0 - name is not IP |
| 41 | */ | 41 | */ |
| 42 | static int | 42 | static int |
| 43 | is_ip(char *name) | 43 | is_ip(const char *name, int len) |
| 44 | { | 44 | { |
| 45 | struct sockaddr_storage ss; | 45 | struct sockaddr_storage ss; |
| 46 | 46 | ||
| 47 | return cifs_convert_address((struct sockaddr *)&ss, name); | 47 | return cifs_convert_address((struct sockaddr *)&ss, name, len); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static int | 50 | static int |
| @@ -54,6 +54,10 @@ dns_resolver_instantiate(struct key *key, const void *data, | |||
| 54 | int rc = 0; | 54 | int rc = 0; |
| 55 | char *ip; | 55 | char *ip; |
| 56 | 56 | ||
| 57 | /* make sure this looks like an address */ | ||
| 58 | if (!is_ip(data, datalen)) | ||
| 59 | return -EINVAL; | ||
| 60 | |||
| 57 | ip = kmalloc(datalen + 1, GFP_KERNEL); | 61 | ip = kmalloc(datalen + 1, GFP_KERNEL); |
| 58 | if (!ip) | 62 | if (!ip) |
| 59 | return -ENOMEM; | 63 | return -ENOMEM; |
| @@ -61,12 +65,6 @@ dns_resolver_instantiate(struct key *key, const void *data, | |||
| 61 | memcpy(ip, data, datalen); | 65 | memcpy(ip, data, datalen); |
| 62 | ip[datalen] = '\0'; | 66 | ip[datalen] = '\0'; |
| 63 | 67 | ||
| 64 | /* make sure this looks like an address */ | ||
| 65 | if (!is_ip(ip)) { | ||
| 66 | kfree(ip); | ||
| 67 | return -EINVAL; | ||
| 68 | } | ||
| 69 | |||
| 70 | key->type_data.x[0] = datalen; | 68 | key->type_data.x[0] = datalen; |
| 71 | key->payload.data = ip; | 69 | key->payload.data = ip; |
| 72 | 70 | ||
| @@ -93,7 +91,7 @@ struct key_type key_type_dns_resolver = { | |||
| 93 | * unc - server UNC | 91 | * unc - server UNC |
| 94 | * output: | 92 | * output: |
| 95 | * *ip_addr - pointer to server ip, caller responcible for freeing it. | 93 | * *ip_addr - pointer to server ip, caller responcible for freeing it. |
| 96 | * return 0 on success | 94 | * return the length of the returned string on success |
| 97 | */ | 95 | */ |
| 98 | int | 96 | int |
| 99 | dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) | 97 | dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) |
| @@ -131,7 +129,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) | |||
| 131 | memcpy(name, unc+2, len); | 129 | memcpy(name, unc+2, len); |
| 132 | name[len] = 0; | 130 | name[len] = 0; |
| 133 | 131 | ||
| 134 | if (is_ip(name)) { | 132 | if (is_ip(name, len)) { |
| 135 | cFYI(1, "%s: it is IP, skipping dns upcall: %s", | 133 | cFYI(1, "%s: it is IP, skipping dns upcall: %s", |
| 136 | __func__, name); | 134 | __func__, name); |
| 137 | data = name; | 135 | data = name; |
| @@ -164,7 +162,7 @@ skip_upcall: | |||
| 164 | name, | 162 | name, |
| 165 | *ip_addr | 163 | *ip_addr |
| 166 | ); | 164 | ); |
| 167 | rc = 0; | 165 | rc = len; |
| 168 | } else { | 166 | } else { |
| 169 | rc = -ENOMEM; | 167 | rc = -ENOMEM; |
| 170 | } | 168 | } |
