nfsd: don't alloc under spinlock in rpc_parse_scope_id
[ Upstream commit 9b6e27d01adcec58e046c624874f8a124e8b07ec ] Dan Carpenter says: The patchd20c11d86d
: "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 <dan.carpenter@oracle.com> Fixes:d20c11d86d
("nfsd: Protect session creation and client...") Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
602ab1fd40
commit
f3492c4a92
@@ -162,8 +162,10 @@ static int rpc_parse_scope_id(struct net *net, const char *buf,
|
|||||||
const size_t buflen, const char *delim,
|
const size_t buflen, const char *delim,
|
||||||
struct sockaddr_in6 *sin6)
|
struct sockaddr_in6 *sin6)
|
||||||
{
|
{
|
||||||
char *p;
|
char p[IPV6_SCOPE_ID_LEN + 1];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
u32 scope_id = 0;
|
||||||
|
struct net_device *dev;
|
||||||
|
|
||||||
if ((buf + buflen) == delim)
|
if ((buf + buflen) == delim)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -175,31 +177,25 @@ static int rpc_parse_scope_id(struct net *net, const char *buf,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
len = (buf + buflen) - delim - 1;
|
len = (buf + buflen) - delim - 1;
|
||||||
p = kmemdup_nul(delim + 1, len, GFP_KERNEL);
|
if (len > IPV6_SCOPE_ID_LEN)
|
||||||
if (p) {
|
return 0;
|
||||||
u32 scope_id = 0;
|
|
||||||
struct net_device *dev;
|
memcpy(p, delim + 1, len);
|
||||||
|
p[len] = 0;
|
||||||
|
|
||||||
dev = dev_get_by_name(net, p);
|
dev = dev_get_by_name(net, p);
|
||||||
if (dev != NULL) {
|
if (dev != NULL) {
|
||||||
scope_id = dev->ifindex;
|
scope_id = dev->ifindex;
|
||||||
dev_put(dev);
|
dev_put(dev);
|
||||||
} else {
|
} else {
|
||||||
if (kstrtou32(p, 10, &scope_id) != 0) {
|
if (kstrtou32(p, 10, &scope_id) != 0)
|
||||||
kfree(p);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
kfree(p);
|
|
||||||
|
|
||||||
sin6->sin6_scope_id = scope_id;
|
sin6->sin6_scope_id = scope_id;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
|
static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
|
||||||
struct sockaddr *sap, const size_t salen)
|
struct sockaddr *sap, const size_t salen)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user