From patchwork Wed Jun 1 12:44:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12866855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4693BC433EF for ; Wed, 1 Jun 2022 12:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 193E38D0006; Wed, 1 Jun 2022 08:23:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 075EF8D0010; Wed, 1 Jun 2022 08:23:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE39A8D000E; Wed, 1 Jun 2022 08:23:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C64DF8D0006 for ; Wed, 1 Jun 2022 08:23:27 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 781EB33EB5 for ; Wed, 1 Jun 2022 12:23:27 +0000 (UTC) X-FDA: 79529582454.15.08C1E7C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 0B229C008A for ; Wed, 1 Jun 2022 12:22:46 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LCpD73fdjzgYWl; Wed, 1 Jun 2022 20:21:43 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:23 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:22 +0800 From: Chen Wandun To: , , , CC: Subject: [PATCH 1/4] mm/shmem: check return value of shmem_init_inodecache Date: Wed, 1 Jun 2022 20:44:14 +0800 Message-ID: <20220601124417.2872001-2-chenwandun@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com> References: <20220601124417.2872001-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Stat-Signature: o6upgb44j51qet5p9ztiuhed1qhxdji3 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0B229C008A X-HE-Tag: 1654086166-582078 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It will result in null pointer access if shmem_init_inodecache fail, so check return value of shmem_init_inodecache Signed-off-by: Chen Wandun --- mm/shmem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d55dd972023a..80c361c3d82c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3776,11 +3776,13 @@ static void shmem_init_inode(void *foo) inode_init_once(&info->vfs_inode); } -static void shmem_init_inodecache(void) +static struct kmem_cache *shmem_init_inodecache(void) { shmem_inode_cachep = kmem_cache_create("shmem_inode_cache", sizeof(struct shmem_inode_info), 0, SLAB_PANIC|SLAB_ACCOUNT, shmem_init_inode); + + return shmem_inode_cachep; } static void shmem_destroy_inodecache(void) @@ -3924,7 +3926,10 @@ void __init shmem_init(void) { int error; - shmem_init_inodecache(); + if (!shmem_init_inodecache()) { + error = -ENOMEM; + goto out2; + } error = register_filesystem(&shmem_fs_type); if (error) { From patchwork Wed Jun 1 12:44:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12866857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D2D1C433FE for ; Wed, 1 Jun 2022 12:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 431BA8D0011; Wed, 1 Jun 2022 08:23:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BDF98D000E; Wed, 1 Jun 2022 08:23:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25B658D0011; Wed, 1 Jun 2022 08:23:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 138C78D000E for ; Wed, 1 Jun 2022 08:23:30 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DAD7D60A4E for ; Wed, 1 Jun 2022 12:23:29 +0000 (UTC) X-FDA: 79529582538.06.E4A797F Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf14.hostedemail.com (Postfix) with ESMTP id 8310C10003B for ; Wed, 1 Jun 2022 12:23:28 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LCpFs2319zDqWt; Wed, 1 Jun 2022 20:23:13 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:24 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:24 +0800 From: Chen Wandun To: , , , CC: Subject: [PATCH 2/4] mm/shmem: return -EINVAL for addr not PAGE_SIZE aligned Date: Wed, 1 Jun 2022 20:44:15 +0800 Message-ID: <20220601124417.2872001-3-chenwandun@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com> References: <20220601124417.2872001-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Stat-Signature: jndnm9wzmqk6n1h1g79kfssdi4qruifk X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=chenwandun@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8310C10003B X-HE-Tag: 1654086208-448636 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If addr is not PAGE_SIZE aligned, return -EINVAL directly. Besides, use macro offset_in_page to check addr is not PAGE_SIZE aligned case. Signed-off-by: Chen Wandun --- mm/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 80c361c3d82c..1136dd7da9e5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2143,8 +2143,8 @@ unsigned long shmem_get_unmapped_area(struct file *file, return addr; if (IS_ERR_VALUE(addr)) return addr; - if (addr & ~PAGE_MASK) - return addr; + if (offset_in_page(addr)) + return -EINVAL; if (addr > TASK_SIZE - len) return addr; @@ -2197,7 +2197,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, inflated_addr = get_area(NULL, uaddr, inflated_len, 0, flags); if (IS_ERR_VALUE(inflated_addr)) return addr; - if (inflated_addr & ~PAGE_MASK) + if (offset_in_page(inflated_addr)) return addr; inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1); From patchwork Wed Jun 1 12:44:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12866856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19335C433F5 for ; Wed, 1 Jun 2022 12:23:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB6CC8D0010; Wed, 1 Jun 2022 08:23:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9555E8D000E; Wed, 1 Jun 2022 08:23:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F28F8D0010; Wed, 1 Jun 2022 08:23:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 694418D000E for ; Wed, 1 Jun 2022 08:23:29 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 3AE4C802A0 for ; Wed, 1 Jun 2022 12:23:29 +0000 (UTC) X-FDA: 79529582538.26.B57D0E0 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf05.hostedemail.com (Postfix) with ESMTP id D30FF10005C for ; Wed, 1 Jun 2022 12:22:53 +0000 (UTC) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LCpF718ZWzjXHt; Wed, 1 Jun 2022 20:22:35 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:25 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:25 +0800 From: Chen Wandun To: , , , CC: Subject: [PATCH 3/4] mm/shmem: return error code directly Date: Wed, 1 Jun 2022 20:44:16 +0800 Message-ID: <20220601124417.2872001-4-chenwandun@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com> References: <20220601124417.2872001-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D30FF10005C Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com X-Stat-Signature: 6tnjfkms1rkn9p9uyp7umixkmjxj4nkj X-Rspam-User: X-HE-Tag: 1654086173-459244 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If [addr, addr + len) beyond TASK_SIZE, return error code directly. No need to check this case in caller. Signed-off-by: Chen Wandun --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1136dd7da9e5..ca04f3975a8a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2146,7 +2146,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, if (offset_in_page(addr)) return -EINVAL; if (addr > TASK_SIZE - len) - return addr; + return -ENOMEM; if (shmem_huge == SHMEM_HUGE_DENY) return addr; From patchwork Wed Jun 1 12:44:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12866858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B476C433F5 for ; Wed, 1 Jun 2022 12:23:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6758C8D0012; Wed, 1 Jun 2022 08:23:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AE838D000E; Wed, 1 Jun 2022 08:23:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FA6F8D0012; Wed, 1 Jun 2022 08:23:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 24C178D000E for ; Wed, 1 Jun 2022 08:23:31 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F06EE34279 for ; Wed, 1 Jun 2022 12:23:30 +0000 (UTC) X-FDA: 79529582580.31.3E44367 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf29.hostedemail.com (Postfix) with ESMTP id 09F4F12005C for ; Wed, 1 Jun 2022 12:23:16 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LCpDC2Bw4z1K9BD; Wed, 1 Jun 2022 20:21:47 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:27 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 20:23:26 +0800 From: Chen Wandun To: , , , CC: Subject: [PATCH 4/4] mm/shmem: rework calculation of inflated_addr in shmem_get_unmapped_area Date: Wed, 1 Jun 2022 20:44:17 +0800 Message-ID: <20220601124417.2872001-5-chenwandun@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com> References: <20220601124417.2872001-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=chenwandun@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 09F4F12005C X-Rspam-User: X-Stat-Signature: zmigmey7syznkq5tohpbarn95ma6rxwn X-HE-Tag: 1654086196-222977 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In function shmem_get_unmapped_area, inflated_offset and offset are unsigned long, it will result in underflow when offset below inflated_offset, a little confusing, no functional change. Signed-off-by: Chen Wandun --- mm/shmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ca04f3975a8a..f12163bd0f69 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2201,9 +2201,12 @@ unsigned long shmem_get_unmapped_area(struct file *file, return addr; inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1); - inflated_addr += offset - inflated_offset; - if (inflated_offset > offset) + if (offset > inflated_offset) + inflated_addr += offset - inflated_offset; + else if (offset < inflated_offset) { + inflated_addr -= inflated_offset - offset; inflated_addr += HPAGE_PMD_SIZE; + } if (inflated_addr > TASK_SIZE - len) return addr;