Skip to content

Commit affd9a8

Browse files
committed
Merge branch 'for-linus' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs fixes from Jeff Layton. * 'for-linus' of git://git.samba.org/sfrench/cifs-2.6: cifs: Do not lookup hashed negative dentry in cifs_atomic_open cifs: fix potential buffer overrun in cifs.idmap handling code
2 parents 487bda5 + 3798f47 commit affd9a8

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

‎fs/cifs/cifsacl.c‎

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr)
224224
}
225225
}
226226

227+
static void
228+
cifs_copy_sid(struct cifs_sid *dst, const struct cifs_sid *src)
229+
{
230+
memcpy(dst, src, sizeof(*dst));
231+
dst->num_subauth = min_t(u8, src->num_subauth, NUM_SUBAUTHS);
232+
}
233+
227234
static void
228235
id_rb_insert(struct rb_root *root, struct cifs_sid *sidptr,
229236
struct cifs_sid_id **psidid, char *typestr)
@@ -248,7 +255,7 @@ id_rb_insert(struct rb_root *root, struct cifs_sid *sidptr,
248255
}
249256
}
250257

251-
memcpy(&(*psidid)->sid, sidptr, sizeof(struct cifs_sid));
258+
cifs_copy_sid(&(*psidid)->sid, sidptr);
252259
(*psidid)->time = jiffies - (SID_MAP_RETRY + 1);
253260
(*psidid)->refcount = 0;
254261

@@ -354,7 +361,7 @@ id_to_sid(unsigned long cid, uint sidtype, struct cifs_sid *ssid)
354361
* any fields of the node after a reference is put .
355362
*/
356363
if (test_bit(SID_ID_MAPPED, &psidid->state)) {
357-
memcpy(ssid, &psidid->sid, sizeof(struct cifs_sid));
364+
cifs_copy_sid(ssid, &psidid->sid);
358365
psidid->time = jiffies; /* update ts for accessing */
359366
goto id_sid_out;
360367
}
@@ -370,14 +377,14 @@ id_to_sid(unsigned long cid, uint sidtype, struct cifs_sid *ssid)
370377
if (IS_ERR(sidkey)) {
371378
rc = -EINVAL;
372379
cFYI(1, "%s: Can't map and id to a SID", __func__);
380+
} else if (sidkey->datalen < sizeof(struct cifs_sid)) {
381+
rc = -EIO;
382+
cFYI(1, "%s: Downcall contained malformed key "
383+
"(datalen=%hu)", __func__, sidkey->datalen);
373384
} else {
374385
lsid = (struct cifs_sid *)sidkey->payload.data;
375-
memcpy(&psidid->sid, lsid,
376-
sidkey->datalen < sizeof(struct cifs_sid) ?
377-
sidkey->datalen : sizeof(struct cifs_sid));
378-
memcpy(ssid, &psidid->sid,
379-
sidkey->datalen < sizeof(struct cifs_sid) ?
380-
sidkey->datalen : sizeof(struct cifs_sid));
386+
cifs_copy_sid(&psidid->sid, lsid);
387+
cifs_copy_sid(ssid, &psidid->sid);
381388
set_bit(SID_ID_MAPPED, &psidid->state);
382389
key_put(sidkey);
383390
kfree(psidid->sidstr);
@@ -396,7 +403,7 @@ id_to_sid(unsigned long cid, uint sidtype, struct cifs_sid *ssid)
396403
return rc;
397404
}
398405
if (test_bit(SID_ID_MAPPED, &psidid->state))
399-
memcpy(ssid, &psidid->sid, sizeof(struct cifs_sid));
406+
cifs_copy_sid(ssid, &psidid->sid);
400407
else
401408
rc = -EINVAL;
402409
}
@@ -675,8 +682,6 @@ int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid)
675682
static void copy_sec_desc(const struct cifs_ntsd *pntsd,
676683
struct cifs_ntsd *pnntsd, __u32 sidsoffset)
677684
{
678-
int i;
679-
680685
struct cifs_sid *owner_sid_ptr, *group_sid_ptr;
681686
struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr;
682687

@@ -692,26 +697,14 @@ static void copy_sec_desc(const struct cifs_ntsd *pntsd,
692697
owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
693698
le32_to_cpu(pntsd->osidoffset));
694699
nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset);
695-
696-
nowner_sid_ptr->revision = owner_sid_ptr->revision;
697-
nowner_sid_ptr->num_subauth = owner_sid_ptr->num_subauth;
698-
for (i = 0; i < 6; i++)
699-
nowner_sid_ptr->authority[i] = owner_sid_ptr->authority[i];
700-
for (i = 0; i < 5; i++)
701-
nowner_sid_ptr->sub_auth[i] = owner_sid_ptr->sub_auth[i];
700+
cifs_copy_sid(nowner_sid_ptr, owner_sid_ptr);
702701

703702
/* copy group sid */
704703
group_sid_ptr = (struct cifs_sid *)((char *)pntsd +
705704
le32_to_cpu(pntsd->gsidoffset));
706705
ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset +
707706
sizeof(struct cifs_sid));
708-
709-
ngroup_sid_ptr->revision = group_sid_ptr->revision;
710-
ngroup_sid_ptr->num_subauth = group_sid_ptr->num_subauth;
711-
for (i = 0; i < 6; i++)
712-
ngroup_sid_ptr->authority[i] = group_sid_ptr->authority[i];
713-
for (i = 0; i < 5; i++)
714-
ngroup_sid_ptr->sub_auth[i] = group_sid_ptr->sub_auth[i];
707+
cifs_copy_sid(ngroup_sid_ptr, group_sid_ptr);
715708

716709
return;
717710
}
@@ -1120,8 +1113,7 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
11201113
kfree(nowner_sid_ptr);
11211114
return rc;
11221115
}
1123-
memcpy(owner_sid_ptr, nowner_sid_ptr,
1124-
sizeof(struct cifs_sid));
1116+
cifs_copy_sid(owner_sid_ptr, nowner_sid_ptr);
11251117
kfree(nowner_sid_ptr);
11261118
*aclflag = CIFS_ACL_OWNER;
11271119
}
@@ -1139,8 +1131,7 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
11391131
kfree(ngroup_sid_ptr);
11401132
return rc;
11411133
}
1142-
memcpy(group_sid_ptr, ngroup_sid_ptr,
1143-
sizeof(struct cifs_sid));
1134+
cifs_copy_sid(group_sid_ptr, ngroup_sid_ptr);
11441135
kfree(ngroup_sid_ptr);
11451136
*aclflag = CIFS_ACL_GROUP;
11461137
}

‎fs/cifs/dir.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,16 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
398398
* in network traffic in the other paths.
399399
*/
400400
if (!(oflags & O_CREAT)) {
401-
struct dentry *res = cifs_lookup(inode, direntry, 0);
401+
struct dentry *res;
402+
403+
/*
404+
* Check for hashed negative dentry. We have already revalidated
405+
* the dentry and it is fine. No need to perform another lookup.
406+
*/
407+
if (!d_unhashed(direntry))
408+
return -ENOENT;
409+
410+
res = cifs_lookup(inode, direntry, 0);
402411
if (IS_ERR(res))
403412
return PTR_ERR(res);
404413

0 commit comments

Comments
 (0)