From patchwork Wed Nov 11 01:05:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haotian Li X-Patchwork-Id: 1397856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CW64s0zvkz9s0b for ; Wed, 11 Nov 2020 12:06:37 +1100 (AEDT) Received: from localhost ([::1]:35838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kceap-0007nP-54 for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2020 20:06:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kceaU-0007hp-3T for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:06:14 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kceaS-0007Pd-2n for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:06:13 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CW6472CxXzhkCg; Wed, 11 Nov 2020 09:05:59 +0800 (CST) Received: from [10.174.178.136] (10.174.178.136) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 09:05:57 +0800 Subject: [PATCH 1/3] tools/virtiofsd/buffer.c: check whether buf is NULL in fuse_bufvec_advance func From: Haotian Li To: , References: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> Message-ID: <29fc87c2-b87c-4c34-40d4-75381f228849@huawei.com> Date: Wed, 11 Nov 2020 09:05:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0 MIME-Version: 1.0 In-Reply-To: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> X-Originating-IP: [10.174.178.136] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.191; envelope-from=lihaotian9@huawei.com; helo=szxga05-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 20:06:08 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linfeilong@huawei.com, liuzhiqiang26@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In fuse_bufvec_advance func, calling fuse_bufvec_current func may return NULL, so we should check whether buf is NULL before using it. Signed-off-by: Haotian Li Signed-off-by: Zhiqiang Liu Reviewed-by: Dr. David Alan Gilbert --- tools/virtiofsd/buffer.c | 4 ++++ 1 file changed, 4 insertions(+) -- diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c index 27c1377f22..bdc608c221 100644 --- a/tools/virtiofsd/buffer.c +++ b/tools/virtiofsd/buffer.c @@ -246,6 +246,10 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len) { const struct fuse_buf *buf = fuse_bufvec_current(bufv); + if (!buf) { + return 0; + } + bufv->off += len; assert(bufv->off <= buf->size); if (bufv->off == buf->size) { From patchwork Wed Nov 11 01:09:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haotian Li X-Patchwork-Id: 1397857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CW68l0X2Vz9s0b for ; Wed, 11 Nov 2020 12:09:59 +1100 (AEDT) Received: from localhost ([::1]:38486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcee5-0000jB-0H for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2020 20:09:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcedc-0000hR-Fz for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:09:28 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kceda-0007tb-LJ for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:09:28 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CW67q5HLszLwrn; Wed, 11 Nov 2020 09:09:11 +0800 (CST) Received: from [10.174.178.136] (10.174.178.136) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 09:09:13 +0800 Subject: [PATCH 2/3] virtiofsd: check whether lo_map_reserve returns NULL in, main func From: Haotian Li To: , References: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> Message-ID: <48887813-1c95-048c-6d10-48e3dd2bac71@huawei.com> Date: Wed, 11 Nov 2020 09:09:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0 MIME-Version: 1.0 In-Reply-To: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> X-Originating-IP: [10.174.178.136] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.191; envelope-from=lihaotian9@huawei.com; helo=szxga05-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 20:06:08 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linfeilong@huawei.com, liuzhiqiang26@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In main func, func lo_map_reserve is called without NULL check. If reallocing new_elems fails in func lo_map_grow, the func lo_map_reserve may return NULL. We should check whether lo_map_reserve returns NULL before using it. Signed-off-by: Haotian Li Signed-off-by: Zhiqiang Liu Reviewed-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index ec1008bceb..3e9bbc7a04 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3433,6 +3433,7 @@ int main(int argc, char *argv[]) .proc_self_fd = -1, }; struct lo_map_elem *root_elem; + struct lo_map_elem *reserve_elem; int ret = -1; /* Don't mask creation mode, kernel already did that */ @@ -3452,8 +3453,17 @@ int main(int argc, char *argv[]) * [1] Root inode */ lo_map_init(&lo.ino_map); - lo_map_reserve(&lo.ino_map, 0)->in_use = false; + reserve_elem = lo_map_reserve(&lo.ino_map, 0); + if (!reserve_elem) { + fuse_log(FUSE_LOG_ERR, "failed to alloc reserve_elem.\n"); + goto err_out1; + } + reserve_elem->in_use = false; root_elem = lo_map_reserve(&lo.ino_map, lo.root.fuse_ino); + if (!root_elem) { + fuse_log(FUSE_LOG_ERR, "failed to alloc root_elem.\n"); + goto err_out1; + } root_elem->inode = &lo.root; lo_map_init(&lo.dirp_map); From patchwork Wed Nov 11 01:10:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haotian Li X-Patchwork-Id: 1397858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CW6BM5Ppxz9s0b for ; Wed, 11 Nov 2020 12:11:23 +1100 (AEDT) Received: from localhost ([::1]:40804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcefR-0001tI-P0 for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2020 20:11:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcef6-0001rK-0s for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:11:00 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2138) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcef4-0008DP-5Y for qemu-devel@nongnu.org; Tue, 10 Nov 2020 20:10:59 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CW69V4ZHqz74nC; Wed, 11 Nov 2020 09:10:38 +0800 (CST) Received: from [10.174.178.136] (10.174.178.136) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 09:10:39 +0800 Subject: [PATCH 3/3] virtiofsd: check whether strdup lo.source return NULL in main func From: Haotian Li To: , References: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> Message-ID: Date: Wed, 11 Nov 2020 09:10:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0 MIME-Version: 1.0 In-Reply-To: <3477d902-ace9-1aa1-531a-9d20d6e93a05@huawei.com> X-Originating-IP: [10.174.178.136] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.35; envelope-from=lihaotian9@huawei.com; helo=szxga07-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 20:10:47 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linfeilong@huawei.com, liuzhiqiang26@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In main func, strdup lo.source may fail. So check whether strdup lo.source return NULL before using it. Signed-off-by: Haotian Li Signed-off-by: Zhiqiang Liu Reviewed-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 4 ++++ 1 file changed, 4 insertions(+) -- diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index 3e9bbc7a04..0c11134fb5 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3525,6 +3525,10 @@ int main(int argc, char *argv[]) } } else { lo.source = strdup("/"); + if (!lo.source) { + fuse_log(FUSE_LOG_ERR, "failed to strdup source\n"); + goto err_out1; + } } if (lo.xattrmap) {