mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 16:37:50 +00:00
net/9p: Initialize the iounit field during fid creation
commitaa7aeee169
upstream. Ensure that the fid's iounit field is set to zero when a new fid is created. Certain 9P operations, such as OPEN and CREATE, allow the server to reply with an iounit size which the client code assigns to the p9_fid struct shortly after the fid is created by p9_fid_create(). On the other hand, an XATTRWALK operation doesn't allow for the server to specify an iounit value. The iounit field of the newly allocated p9_fid struct remained uninitialized in that case. Depending on allocation patterns, the iounit value could have been something reasonable that was carried over from previously freed fids or, in the worst case, could have been arbitrary values from non-fid related usages of the memory location. The bug was detected in the Windows Subsystem for Linux 2 (WSL2) kernel after the uninitialized iounit field resulted in the typical sequence of two getxattr(2) syscalls, one to get the size of an xattr and another after allocating a sufficiently sized buffer to fit the xattr value, to hit an unexpected ERANGE error in the second call to getxattr(2). An uninitialized iounit field would sometimes force rsize to be smaller than the xattr value size in p9_client_read_once() and the 9P server in WSL refused to chunk up the READ on the attr_fid and, instead, returned ERANGE to the client. The virtfs server in QEMU seems happy to chunk up the READ and this problem goes undetected there. Link: https://lkml.kernel.org/r/20220710141402.803295-1-tyhicks@linux.microsoft.com Fixes:ebf46264a0
("fs/9p: Add support user. xattr") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org> [tyhicks: Adjusted context due to: - Lack of fid refcounting introduced in v5.11 commit6636b6dcc3
("9p: add refcount to p9_fid struct") - Difference in how buffer sizes are specified v5.16 commit6e195b0f7c
("9p: fix a bunch of checkpatch warnings") - Reimplementation of the fidlist as an IDR in v4.19 commitf28cdf0430
("9p: Replace the fidlist with an IDR")] Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5f776b8b32
commit
918ce0827e
1 changed files with 1 additions and 3 deletions
|
@ -915,7 +915,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt)
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt);
|
p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt);
|
||||||
fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
|
fid = kzalloc(sizeof(struct p9_fid), GFP_KERNEL);
|
||||||
if (!fid)
|
if (!fid)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
|
@ -926,11 +926,9 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt)
|
||||||
}
|
}
|
||||||
fid->fid = ret;
|
fid->fid = ret;
|
||||||
|
|
||||||
memset(&fid->qid, 0, sizeof(struct p9_qid));
|
|
||||||
fid->mode = -1;
|
fid->mode = -1;
|
||||||
fid->uid = current_fsuid();
|
fid->uid = current_fsuid();
|
||||||
fid->clnt = clnt;
|
fid->clnt = clnt;
|
||||||
fid->rdir = NULL;
|
|
||||||
spin_lock_irqsave(&clnt->lock, flags);
|
spin_lock_irqsave(&clnt->lock, flags);
|
||||||
list_add(&fid->flist, &clnt->fidlist);
|
list_add(&fid->flist, &clnt->fidlist);
|
||||||
spin_unlock_irqrestore(&clnt->lock, flags);
|
spin_unlock_irqrestore(&clnt->lock, flags);
|
||||||
|
|
Loading…
Reference in a new issue