2012-08-07 15:30:33

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH] NFS: Clear key construction data if the idmap upcall fails

From: Bryan Schumaker <[email protected]>

idmap_pipe_downcall already clears this field if the upcall succeeds,
but if it fails (rpc.idmapd isn't running) the field will still be set
on the next call triggering a BUG_ON().

Signed-off-by: Bryan Schumaker <[email protected]>
---
fs/nfs/idmap.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index b701358..645cfe7 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -683,10 +683,12 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,

ret = rpc_queue_upcall(idmap->idmap_pipe, msg);
if (ret < 0)
- goto out2;
+ goto out3;

return ret;

+out3:
+ idmap->idmap_key_cons = NULL;
out2:
kfree(im);
out1:
--
1.7.11.4



2012-08-07 15:44:21

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH] NFS: Clear key construction data if the idmap upcall fails

T24gVHVlLCAyMDEyLTA4LTA3IGF0IDExOjMwIC0wNDAwLCBianNjaHVtYUBuZXRhcHAuY29tIHdy
b3RlOg0KPiBGcm9tOiBCcnlhbiBTY2h1bWFrZXIgPGJqc2NodW1hQG5ldGFwcC5jb20+DQo+IA0K
PiBpZG1hcF9waXBlX2Rvd25jYWxsIGFscmVhZHkgY2xlYXJzIHRoaXMgZmllbGQgaWYgdGhlIHVw
Y2FsbCBzdWNjZWVkcywNCj4gYnV0IGlmIGl0IGZhaWxzIChycGMuaWRtYXBkIGlzbid0IHJ1bm5p
bmcpIHRoZSBmaWVsZCB3aWxsIHN0aWxsIGJlIHNldA0KPiBvbiB0aGUgbmV4dCBjYWxsIHRyaWdn
ZXJpbmcgYSBCVUdfT04oKS4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IEJyeWFuIFNjaHVtYWtlciA8
YmpzY2h1bWFAbmV0YXBwLmNvbT4NCj4gLS0tDQo+IC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mVsZWFzZSB0aGF0IG11dGV4LiBUaGF0DQpsZWF2ZXMgb25lIHBvc3NpYmxlIHJhY2Ug
aW4gd2hpY2ggdGhlIGlkbWFwLT5pZG1hcF9rZXlfY29ucyBpcyBjbGVhcmVkDQp3aGlsZSB3ZSdy
ZSBpbiBpZG1hcF9waXBlX2Rvd25jYWxsLiBPbmUgd2F5IHRvIHNvbHZlIHRoYXQgcmFjZSBpcyB0
byB1c2UNCmEgc2Vjb25kIG11dGV4IChzZWUgdGhlIG9yaWdpbmFsIGlkbWFwcGVyIGRlc2lnbiBm
cm9tIGJlZm9yZSB5b3VyDQpjaGFuZ2VzKSB0byBlbnN1cmUgdGhhdCBub3RoaW5nIGNsZWFycyBp
ZG1hcF9rZXlfY29ucyB3aGlsZSB3ZSdyZSBpbg0KaWRtYXBfcGlwZV9kb3duY2FsbC4NCg0KLS0g
DQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lcg0KDQpOZXRBcHAN
ClRyb25kLk15a2xlYnVzdEBuZXRhcHAuY29tDQp3d3cubmV0YXBwLmNvbQ0KDQo=

2012-08-07 15:52:56

by Anna Schumaker

[permalink] [raw]
Subject: Re: [PATCH] NFS: Clear key construction data if the idmap upcall fails

On 08/07/2012 11:44 AM, Myklebust, Trond wrote:
> On Tue, 2012-08-07 at 11:30 -0400, [email protected] wrote:
>> From: Bryan Schumaker <[email protected]>
>>
>> idmap_pipe_downcall already clears this field if the upcall succeeds,
>> but if it fails (rpc.idmapd isn't running) the field will still be set
>> on the next call triggering a BUG_ON().
>>
>> Signed-off-by: Bryan Schumaker <[email protected]>
>> ---
>> fs/nfs/idmap.c | 16 +++++++++-------
>> 1 file changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
>> index b701358..645cfe7 100644
>> --- a/fs/nfs/idmap.c
>> +++ b/fs/nfs/idmap.c
>> @@ -683,10 +683,12 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
>>
>> ret = rpc_queue_upcall(idmap->idmap_pipe, msg);
>> if (ret < 0)
>> - goto out2;
>> + goto out3;
>>
>> return ret;
>>
>> +out3:
>> + idmap->idmap_key_cons = NULL;
>> out2:
>> kfree(im);
>> out1:
>
> That fixes rpc_queue_upcall failure path, but we still need to deal with
> timeouts and close.
>
> How about the following alternative:
>
> Set idmap->idmap_key_cons after grabbing the mutex in
> nfs_idmap_get_key(), then clear it before you release that mutex. That

The key construction data doesn't exist during nfs_idmap_get_key(). request_key() sets it up to pass to our functions as it works through the keyrings code.

- Bryan

> leaves one possible race in which the idmap->idmap_key_cons is cleared
> while we're in idmap_pipe_downcall. One way to solve that race is to use
> a second mutex (see the original idmapper design from before your
> changes) to ensure that nothing clears idmap_key_cons while we're in
> idmap_pipe_downcall.
>


2012-08-07 16:00:32

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH] NFS: Clear key construction data if the idmap upcall fails

T24gVHVlLCAyMDEyLTA4LTA3IGF0IDExOjUyIC0wNDAwLCBCcnlhbiBTY2h1bWFrZXIgd3JvdGU6
DQo+IE9uIDA4LzA3LzIwMTIgMTE6NDQgQU0sIE15a2xlYnVzdCwgVHJvbmQgd3JvdGU6DQo+ID4g
T24gVHVlLCAyMDEyLTA4LTA3IGF0IDExOjMwIC0wNDAwLCBianNjaHVtYUBuZXRhcHAuY29tIHdy
b3RlOg0KPiA+PiBGcm9tOiBCcnlhbiBTY2h1bWFrZXIgPGJqc2NodW1hQG5ldGFwcC5jb20+DQo+
ID4+DQo+ID4+IGlkbWFwX3BpcGVfZG93bmNhbGwgYWxyZWFkeSBjbGVhcnMgdGhpcyBmaWVsZCBp
ZiB0aGUgdXBjYWxsIHN1Y2NlZWRzLA0KPiA+PiBidXQgaWYgaXQgZmFpbHMgKHJwYy5pZG1hcGQg
aXNuJ3QgcnVubmluZykgdGhlIGZpZWxkIHdpbGwgc3RpbGwgYmUgc2V0DQo+ID4+IG9uIHRoZ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