aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/dns_resolve.c
diff options
context:
space:
mode:
authorSteve French <sfrench@us.ibm.com>2008-09-23 14:46:07 -0400
committerSteve French <sfrench@us.ibm.com>2008-09-23 14:46:07 -0400
commit9d81523480c8c5b07a4899a084b3f4264a575184 (patch)
treea404c0a8c6f88dfef828f0b3be9177097860bde5 /fs/cifs/dns_resolve.c
parentee2fd967fb23c5eecabc8a660ec66fcd79acbd47 (diff)
[CIFS] clean up upcall handling for dns_resolver keys
We're given the datalen in the downcall, so there's no need to do any calls to strlen(). Just keep track of the datalen in the key. Finally, add a sanity check of the data in the downcall to make sure that it looks like a real IP address. Signed-off-by: Jeff Layton <jlayton@redhat.com> Acked-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/dns_resolve.c')
-rw-r--r--fs/cifs/dns_resolve.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index a2e0673e1b08..1e0c1bd8f2e4 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -29,19 +29,55 @@
29#include "cifsproto.h" 29#include "cifsproto.h"
30#include "cifs_debug.h" 30#include "cifs_debug.h"
31 31
32static int dns_resolver_instantiate(struct key *key, const void *data, 32/* Checks if supplied name is IP address
33 * returns:
34 * 1 - name is IP
35 * 0 - name is not IP
36 */
37static int
38is_ip(const char *name)
39{
40 int rc;
41 struct sockaddr_in sin_server;
42 struct sockaddr_in6 sin_server6;
43
44 rc = cifs_inet_pton(AF_INET, name,
45 &sin_server.sin_addr.s_addr);
46
47 if (rc <= 0) {
48 /* not ipv4 address, try ipv6 */
49 rc = cifs_inet_pton(AF_INET6, name,
50 &sin_server6.sin6_addr.in6_u);
51 if (rc > 0)
52 return 1;
53 } else {
54 return 1;
55 }
56 /* we failed translating address */
57 return 0;
58}
59
60static int
61dns_resolver_instantiate(struct key *key, const void *data,
33 size_t datalen) 62 size_t datalen)
34{ 63{
35 int rc = 0; 64 int rc = 0;
36 char *ip; 65 char *ip;
37 66
38 ip = kmalloc(datalen+1, GFP_KERNEL); 67 ip = kmalloc(datalen + 1, GFP_KERNEL);
39 if (!ip) 68 if (!ip)
40 return -ENOMEM; 69 return -ENOMEM;
41 70
42 memcpy(ip, data, datalen); 71 memcpy(ip, data, datalen);
43 ip[datalen] = '\0'; 72 ip[datalen] = '\0';
44 73
74 /* make sure this looks like an address */
75 if (!is_ip((const char *) ip)) {
76 kfree(ip);
77 return -EINVAL;
78 }
79
80 key->type_data.x[0] = datalen;
45 rcu_assign_pointer(key->payload.data, ip); 81 rcu_assign_pointer(key->payload.data, ip);
46 82
47 return rc; 83 return rc;
@@ -62,33 +98,6 @@ struct key_type key_type_dns_resolver = {
62 .match = user_match, 98 .match = user_match,
63}; 99};
64 100
65/* Checks if supplied name is IP address
66 * returns:
67 * 1 - name is IP
68 * 0 - name is not IP
69 */
70static int is_ip(const char *name)
71{
72 int rc;
73 struct sockaddr_in sin_server;
74 struct sockaddr_in6 sin_server6;
75
76 rc = cifs_inet_pton(AF_INET, name,
77 &sin_server.sin_addr.s_addr);
78
79 if (rc <= 0) {
80 /* not ipv4 address, try ipv6 */
81 rc = cifs_inet_pton(AF_INET6, name,
82 &sin_server6.sin6_addr.in6_u);
83 if (rc > 0)
84 return 1;
85 } else {
86 return 1;
87 }
88 /* we failed translating address */
89 return 0;
90}
91
92/* Resolves server name to ip address. 101/* Resolves server name to ip address.
93 * input: 102 * input:
94 * unc - server UNC 103 * unc - server UNC
@@ -140,6 +149,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
140 149
141 rkey = request_key(&key_type_dns_resolver, name, ""); 150 rkey = request_key(&key_type_dns_resolver, name, "");
142 if (!IS_ERR(rkey)) { 151 if (!IS_ERR(rkey)) {
152 len = rkey->type_data.x[0];
143 data = rkey->payload.data; 153 data = rkey->payload.data;
144 } else { 154 } else {
145 cERROR(1, ("%s: unable to resolve: %s", __func__, name)); 155 cERROR(1, ("%s: unable to resolve: %s", __func__, name));
@@ -148,11 +158,9 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
148 158
149skip_upcall: 159skip_upcall:
150 if (data) { 160 if (data) {
151 len = strlen(data); 161 *ip_addr = kmalloc(len + 1, GFP_KERNEL);
152 *ip_addr = kmalloc(len+1, GFP_KERNEL);
153 if (*ip_addr) { 162 if (*ip_addr) {
154 memcpy(*ip_addr, data, len); 163 memcpy(*ip_addr, data, len + 1);
155 (*ip_addr)[len] = '\0';
156 if (!IS_ERR(rkey)) 164 if (!IS_ERR(rkey))
157 cFYI(1, ("%s: resolved: %s to %s", __func__, 165 cFYI(1, ("%s: resolved: %s to %s", __func__,
158 name, 166 name,