Skip to content

Commit 9b6e27d

Browse files
author
J. Bruce Fields
committed
nfsd: don't alloc under spinlock in rpc_parse_scope_id
Dan Carpenter says: The patch d20c11d: "nfsd: Protect session creation and client confirm using client_lock" from Jul 30, 2014, leads to the following Smatch static checker warning: net/sunrpc/addr.c:178 rpc_parse_scope_id() warn: sleeping in atomic context Reported-by: Dan Carpenter <[email protected]> Fixes: d20c11d ("nfsd: Protect session creation and client...") Signed-off-by: J. Bruce Fields <[email protected]>
1 parent e4e737b commit 9b6e27d

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

net/sunrpc/addr.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ static int rpc_parse_scope_id(struct net *net, const char *buf,
162162
const size_t buflen, const char *delim,
163163
struct sockaddr_in6 *sin6)
164164
{
165-
char *p;
165+
char p[IPV6_SCOPE_ID_LEN + 1];
166166
size_t len;
167+
u32 scope_id = 0;
168+
struct net_device *dev;
167169

168170
if ((buf + buflen) == delim)
169171
return 1;
@@ -175,29 +177,23 @@ static int rpc_parse_scope_id(struct net *net, const char *buf,
175177
return 0;
176178

177179
len = (buf + buflen) - delim - 1;
178-
p = kmemdup_nul(delim + 1, len, GFP_KERNEL);
179-
if (p) {
180-
u32 scope_id = 0;
181-
struct net_device *dev;
182-
183-
dev = dev_get_by_name(net, p);
184-
if (dev != NULL) {
185-
scope_id = dev->ifindex;
186-
dev_put(dev);
187-
} else {
188-
if (kstrtou32(p, 10, &scope_id) != 0) {
189-
kfree(p);
190-
return 0;
191-
}
192-
}
193-
194-
kfree(p);
195-
196-
sin6->sin6_scope_id = scope_id;
197-
return 1;
180+
if (len > IPV6_SCOPE_ID_LEN)
181+
return 0;
182+
183+
memcpy(p, delim + 1, len);
184+
p[len] = 0;
185+
186+
dev = dev_get_by_name(net, p);
187+
if (dev != NULL) {
188+
scope_id = dev->ifindex;
189+
dev_put(dev);
190+
} else {
191+
if (kstrtou32(p, 10, &scope_id) != 0)
192+
return 0;
198193
}
199194

200-
return 0;
195+
sin6->sin6_scope_id = scope_id;
196+
return 1;
201197
}
202198

203199
static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,

0 commit comments

Comments
 (0)