Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3470810rwa; Tue, 23 Aug 2022 05:25:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xFgEwv5zcwfIl/RN7CMpqoMHXHfp4bOByZ31vcMIRnNwwSZ3YuHmhGxoEJv/54unJoT1m X-Received: by 2002:a17:902:d58e:b0:172:e985:24a1 with SMTP id k14-20020a170902d58e00b00172e98524a1mr9376151plh.29.1661257521742; Tue, 23 Aug 2022 05:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257521; cv=none; d=google.com; s=arc-20160816; b=XxPe1yfXyE2cAlbDJm5KnZhFzHtFEkFeGLQqQ/SFW8T9Kk8F/CQHywMEdrnVKWJWgo qA22LqN3PeHKayPZUoZSttY4s/Qa5tRZJs0MHdqCj5HcBLsG1sPAhmVT28RyBNrVId5n Ttar5sX27flznuN55TkP8YalrBMdVZWmZPDCjVBLeakenG6K9S7bEnUDAl3IwDmEMlCM vrVI3SpwtsQTWtK8F4WSDmNZGMI89vYcFo77W9U20od6lYsOI+2fBP7G+9ngY0xSsGd4 qn0S2XV3efGHwfB49NgfvPD+iDXUyo+P0blrj7S8WMiI3Ip/MyfbKIarT5PZLE+XUaHs Japw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wyPF8wPsrKxuYtBVYLrJWrKyfJFWFojeMyF9Q34n+/Y=; b=lnuux31Ly9/ReCCEWDDSwMqPk9edzOCNh5ypzgLInXQ+3eGbNgKWsWHK/14vQyhDg7 vYhXAr0DYnNEVKrH0qReWoWeIxrgLTs9Szv9Aq4Uwf9Dy76oRQ+PZmnq26nuurtvMRqW HTz5wJX7tcZht8mNrfI6Fgff9bkrDk85xNABY7MLXL4I3hu2/T30ABZfCoXEaUxezT72 R1MWumSHdVssaXFUBzaBjz95QX8gpLn5M1f2kZ5306ziwZ68LYbytGeB/iQTcxU38TNP U4QnRdV9iHBKbHETg4I6onhD7CIw9p5aO0T3cHKyOY/jbPDaS/HY9J2wCKpap5muG0uX 3gZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CL0mCzVl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q30-20020a63f95e000000b00410ac395252si16462087pgk.512.2022.08.23.05.25.10; Tue, 23 Aug 2022 05:25:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CL0mCzVl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356894AbiHWKzy (ORCPT + 99 others); Tue, 23 Aug 2022 06:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356159AbiHWKtj (ORCPT ); Tue, 23 Aug 2022 06:49:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E154BAB18A; Tue, 23 Aug 2022 02:12:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3B00CB81C88; Tue, 23 Aug 2022 09:12:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88066C433D6; Tue, 23 Aug 2022 09:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245951; bh=aNIRR/iONKqARPCKsB/oCtcZdHegiXVYWMndFZ7GRFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CL0mCzVlKv8wWBJpbjbMYeVJoNchUvLWr6Su1aN8CNMESD+Mf573Nky8sYXp8vfU5 5nvPe+e7U6aRGR7RCm/R6V9qAkGvZAd2PHGlipRJUBD38zMQPzSOWZnhM+wItvDZ9O 32yPIa8RuxlINvWEAVlBHH6Kj6gQ2PyhNWJnw5Ys= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tyler Hicks , Christian Schoenebeck , Dominique Martinet Subject: [PATCH 4.19 210/287] net/9p: Initialize the iounit field during fid creation Date: Tue, 23 Aug 2022 10:26:19 +0200 Message-Id: <20220823080107.996496307@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tyler Hicks commit aa7aeee169480e98cf41d83c01290a37e569be6d 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: ebf46264a004 ("fs/9p: Add support user. xattr") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks Reviewed-by: Christian Schoenebeck Signed-off-by: Dominique Martinet [tyhicks: Adjusted context due to: - Lack of fid refcounting introduced in v5.11 commit 6636b6dcc3db ("9p: add refcount to p9_fid struct") - Difference in how buffer sizes are specified v5.16 commit 6e195b0f7c8e ("9p: fix a bunch of checkpatch warnings")] Signed-off-by: Tyler Hicks Signed-off-by: Greg Kroah-Hartman --- net/9p/client.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- a/net/9p/client.c +++ b/net/9p/client.c @@ -908,16 +908,13 @@ static struct p9_fid *p9_fid_create(stru struct p9_fid *fid; 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) return NULL; - memset(&fid->qid, 0, sizeof(struct p9_qid)); fid->mode = -1; fid->uid = current_fsuid(); fid->clnt = clnt; - fid->rdir = NULL; - fid->fid = 0; idr_preload(GFP_KERNEL); spin_lock_irq(&clnt->lock);