From nobody Fri Dec 19 10:35:53 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 053D614D282 for ; Wed, 28 Aug 2024 07:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724829349; cv=none; b=ZusS/dgFeXbPKPTfXttXTr6oQY6607be0spBJUu0vgqqrQOh106ePXIt9HIBSLV32YB4/gXH9ru88xHcPxp/yq8fRXyPeNN7MZ0yH6GHZO+ovEbK0lslXeRcUUvJAI6/oSebjGxum2W691XRpQH/frFka2W4ycKK8dUmCblQyaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724829349; c=relaxed/simple; bh=MuZuQp+uLztFw2q9cNF/Umod0Y5qwAbjwzRmfx6vBgc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=dhE1kAUtsZCoYzJGc70yowzrkMq8L4oKbWzMagH37/OQzD3utUzf1FsBiHE+tX5XKujP+jGFdi5vmrqOT3YXXJfeQYbgbuN+FZMohLrjQmtKF2o63FFN0Vy5uLdQ5iOhjX4yMMgLm4oU7drEIoh4JSKQjyOpgZgqcFZlY+t8vrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WtwbD2WV4z1HHdj; Wed, 28 Aug 2024 15:12:24 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id EA9D81401F1; Wed, 28 Aug 2024 15:15:43 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 28 Aug 2024 15:15:43 +0800 From: Jinjie Ruan To: , , , , , , CC: Subject: [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation Date: Wed, 28 Aug 2024 15:23:40 +0800 Message-ID: <20240828072340.1249310-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemh500013.china.huawei.com (7.202.181.146) Content-Type: text/plain; charset="utf-8" Let the kmemdup_array() take care about multiplication and possible overflows. Signed-off-by: Jinjie Ruan Reviewed-by: Kees Cook --- kernel/user_namespace.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 0b0b95418b16..aa0b2e47f2f2 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -853,9 +853,8 @@ static int sort_idmaps(struct uid_gid_map *map) cmp_extents_forward, NULL); =20 /* Only copy the memory from forward we actually need. */ - map->reverse =3D kmemdup(map->forward, - map->nr_extents * sizeof(struct uid_gid_extent), - GFP_KERNEL); + map->reverse =3D kmemdup_array(map->forward, map->nr_extents, + sizeof(struct uid_gid_extent), GFP_KERNEL); if (!map->reverse) return -ENOMEM; =20 --=20 2.34.1