Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4420429rdb; Fri, 29 Dec 2023 00:39:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGFs2bIqzN/uyExclvU2VsHnkGuuyOz0R/mb/DC4YA/XZSwJAjsZEw7P/2a/n8amsPUk6s X-Received: by 2002:a17:90b:1bd1:b0:28c:2861:56f9 with SMTP id oa17-20020a17090b1bd100b0028c286156f9mr3167325pjb.96.1703839148915; Fri, 29 Dec 2023 00:39:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703839148; cv=none; d=google.com; s=arc-20160816; b=zj9Yflrol6fuTSRL4OkwbCSFI//KG/Skg7baObwi2oAC2mmQ8eyhXlQ5rgHHFj16fg OwQeBlJbb6x4xMGo26EgouzBlJFVYmu+85zIM4rUafqFpwvCC1mTwXRy9bjwpLP7iXZO hflk+M2hO2FEYJToemBuGU5KbN2qXoD1suWxXOoiP7nIHQxsprzW6UwzYxuElOETPcpQ DSl4NKkUyvI8hFoJOuons4pmBccRTFUd3bQJFmYJDkS8/4r4XTY8IEL5YUQEyJ9A8lF9 2ad+ud/Bgrofb4aZquak+Tpzh4UTf4kSPurVL4xab4QW5pX3YulzY9DAHStVDpC7RKM+ UxIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=4eCIAUbjh9MTyXJKGiI+l552EPsAxzI6kAaXvQ8/w+4=; fh=z0OK8L6GyprJQYDPvIETb1Fe6dbfAA0C+AHWl1Zw7uA=; b=YY5fl/emDGxXBwaXqG9j1/TmCjI11c26mvTcW7IY6V7yk2mYw+hJj8BwabS2O4HAi5 KR3vdfAjiRnzTJRCru8o7sw8E0vW0eRzyjELf5SM/4jGswATEx3bSLM0GFLSvnNKHH+8 lf5b0L1eTVkBAmbVqI281p4vpriUmgDr1sYJrrPguQX+dMUFf6n/QuIaDmf3bcATJxBJ GalRSh3kqz6RCGxFOBwIS6xHt48aL6ieYsJr3YXS+xjQ/b4WEDpU+LGChWM7UCgkdOrM Y/2V+EPR29Ux4eL8nPnXGc6BTA9k2TfRd5GLojxfe972Ap+eTWgnSejNkOL9TKMCoVsb nZdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=GTEGRq7E; spf=pass (google.com: domain of linux-kernel+bounces-12997-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y22-20020a17090a105600b0028cb1d1ce00si628472pjd.39.2023.12.29.00.39.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 00:39:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12997-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=GTEGRq7E; spf=pass (google.com: domain of linux-kernel+bounces-12997-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8E9A4282DB5 for ; Fri, 29 Dec 2023 08:39:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E11B879EF; Fri, 29 Dec 2023 08:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="GTEGRq7E" X-Original-To: linux-kernel@vger.kernel.org Received: from mout.web.de (mout.web.de [212.227.15.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26517487; Fri, 29 Dec 2023 08:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703839128; x=1704443928; i=markus.elfring@web.de; bh=W6yrPNc43adz34gAMxMy30lvqPV/Eba8/b5dIfUxezo=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=GTEGRq7E43WbnsOExZ3FmdrD+SQrDWgukQPygQzUBqPN0GgsmOK2QX/n/trtOu9J Tg1rESZnVGczPK8Y3R6s1iAWKE1Q7irHKp87HxjlOeyKNuemn0BWqiduqdiaw1Vum 3AKU3gFM9ruGWLNqPKNemD583a1YVvGjGF1gvRFyuCQlqa8IX6FTJ7kxYaUhEs5Mb WsQlloqImi8SckEc4QtVI6E+s19XbbpliOjlt4/dHDNsyHvUrjU1oWTpn8IeqeNQj 2vG7JFbPWMz89emLGcOtoOFymeohYdkdArN8685qj78fgCQkIXKVLOXOlfJG5QCwe to1v45rjUEzmKBSSzA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MKdLM-1rXVTg0Ew8-00LPOS; Fri, 29 Dec 2023 09:38:48 +0100 Message-ID: <5745d81c-3c06-4871-9785-12a469870934@web.de> Date: Fri, 29 Dec 2023 09:38:47 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] virtiofs: Improve error handling in virtio_fs_get_tree() Content-Language: en-GB From: Markus Elfring To: virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org, Miklos Szeredi , Stefan Hajnoczi , Vivek Goyal Cc: LKML References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:dIIBJp/wUeMxRDCbjzb05hZ0LyYzeW7/8EGr8swHME9Epop0uR0 XZKg5ysWpkbun+8jJjsN7ht/i7ypbe0HQ9ZbUd7jOZ+RUUT2kztJ9fsQoaYrs3dCBIj3YbO /5HbvkTEjiqjrOvLCRhz42fQgN8hkKr9jaHgkwh4lFtDk08OpaOUKx3+89gRGu3Wehu1nuT OlY9TOZhtJhF+e8yiCqhg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:rMTlxTdEg3Y=;mT6F3lBfUJnD7ni8owTQkOy+hlo 8kC2lDaDeta2038RkVjnn0wJr3oJRh1Kg4d/RGJ8dRkmEkM4xRWBOvd4DM7flB8RdCJbh7wLB vqk9DfK5d29E4k6c1RPShkYkRZxNsC01sH6j+ncv4U3A7OKe6zz4k3JCY270XCpJFYu7MTUgA YYnUhlIr/ZYQ1Zq4xYVkb3thHOmPGWJM0t8iL+ePMOXOPH05z1UKitcRxTn3TqhIQWkdOl3IR iZBvfVIKj1WjGvlO+42BkKLvF7rQtT8kW0wRJPiKk8HMmS9pQ1Rv+5Ljrc0layX0UwPiWzG4t TMFXxoA/YOBYHawpxsv0GlsHBQns1G+8GxiJtDqB52D0IXi1X+Ch2ul+64wCF7HTDWBVs4W69 BqeU7Q4icFO6bjJ8MoNa73DS/wv67GfD0GTwAQksme6kks0bGA/Sk8yczi7jBtKcZFhqdb8qW GVadJ3FXlkx9pDZ8wtbD5/FNtTbnBSdtjSTsgdkafNRbPA6F9FU993L0YpdKqi72DIpqAFNwk WPJCZXZqP1q1X1cSceIaVYTY8wGR5oa+XycGCfsf5R/mUXrtWvMkX6zkWqYIHhXHl2664Xfug 5y8CZ16DbfkMZorabZCc6Skxv6xLKdE2/tsdNV7o+G1y0QO7a8ZKchzSX/pV/BzhdAkF7zcqV mP/oISwJnQCDpCNLgVrgGe999E+JrDs+J2gEejxb047zNIGgEx9g+zz4OpyyT2+bTNAx0lJwn R1bWuS78HlpjZ8IndQoiylOxxrKMhVJwe+t9B24Vxks88BKLFfuT0iMza0v1ZimFOQWeP2Bj4 PjAr1kFT+XJl2dVXxWYwEbI7KfY5GU2e7n4aZiM4zuT/uBmIPnaos8xoV+E+moOnrXkCpj9gv QgrqabNuqIVYpO1Cnj9fSKPN50eHryQRhjhN5qk3xACU1t8hfJXWpf57GqiBMYZ0CUQOtYjr/ KQq6kQ== From: Markus Elfring Date: Fri, 29 Dec 2023 09:15:07 +0100 The kfree() function was called in two cases by the virtio_fs_get_tree() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Thus use another label. * Move an error code assignment into an if branch. * Delete an initialisation (for the variable =E2=80=9Cfc=E2=80=9D) which became unnecessary with this refactoring. Signed-off-by: Markus Elfring =2D-- fs/fuse/virtio_fs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 2f8ba9254c1e..0746f54ec743 100644 =2D-- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1415,10 +1415,10 @@ static int virtio_fs_get_tree(struct fs_context *f= sc) { struct virtio_fs *fs; struct super_block *sb; - struct fuse_conn *fc =3D NULL; + struct fuse_conn *fc; struct fuse_mount *fm; unsigned int virtqueue_size; - int err =3D -EIO; + int err; /* This gets a reference on virtio_fs object. This ptr gets installed * in fc->iq->priv. Once fuse_conn is going away, it calls ->put() @@ -1431,13 +1431,15 @@ static int virtio_fs_get_tree(struct fs_context *f= sc) } virtqueue_size =3D virtqueue_get_vring_size(fs->vqs[VQ_REQUEST].vq); - if (WARN_ON(virtqueue_size <=3D FUSE_HEADER_OVERHEAD)) - goto out_err; + if (WARN_ON(virtqueue_size <=3D FUSE_HEADER_OVERHEAD)) { + err =3D -EIO; + goto lock_mutex; + } err =3D -ENOMEM; fc =3D kzalloc(sizeof(*fc), GFP_KERNEL); if (!fc) - goto out_err; + goto lock_mutex; fm =3D kzalloc(sizeof(*fm), GFP_KERNEL); if (!fm) @@ -1476,6 +1478,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc= ) out_err: kfree(fc); +lock_mutex: mutex_lock(&virtio_fs_mutex); virtio_fs_put(fs); mutex_unlock(&virtio_fs_mutex); =2D- 2.43.0