From patchwork Sun May 28 16:20:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13257865 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 1F49AC77B7C for ; Sun, 28 May 2023 16:20:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35FF36B0071; Sun, 28 May 2023 12:20:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30EE26B0074; Sun, 28 May 2023 12:20:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D6386B0075; Sun, 28 May 2023 12:20:33 -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 0D3A26B0071 for ; Sun, 28 May 2023 12:20:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BC682ADC6C for ; Sun, 28 May 2023 16:20:32 +0000 (UTC) X-FDA: 80840176704.12.D5B06DF Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by imf20.hostedemail.com (Postfix) with ESMTP id E8A241C0015 for ; Sun, 28 May 2023 16:20:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685290831; a=rsa-sha256; cv=none; b=mdESdVlgILldPO9ZyDBAm5Be9ctxXbDkNzYjRTJAzCjE2peSIgWC9VJtYKjlHpexaKBkfb G0F+zpSPeswPrsaYFwUqmagYDJnqE66D2LkXxp8nLEpKdVqTmYMsMAmlLJgAVgAy6+vNGG aMTgQEerG2bFG2hkh6J/iBSD+65SyCs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685290831; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; b=xVE+pmuFBFywaX/6iEcKqb1brN7qljH9nW9AM4XbBd+u40Vmv736s+Dbc4gYh6+ffeUdlo xKgmjdWLXRl86dVBR+t8uDtVHgs5f30I1lD1ffSyc1nkMUTnTizXfA0mv6QqJlbSrRUAot r6QWh/cPcRYZJRWVJlUjtGnxuIH7/z4= Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 3J87qJcsWrDwx3J87qjZRk; Sun, 28 May 2023 18:20:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685290829; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; h=From:To:Cc:Subject:Date; b=KVeczUZ2SyAWnA9n3+aJnOifGCiTgEBfhm1Wso9EJlktFte7I/K8YRWaX0PD1LAA+ TyZ45qzvlxznn3FHzzU/LgAHEWWLn5J1J/FW9lQFLfhvBA0W+f/l2ZD5tz2osdtA0x Rnzuzet0WwEtNtln/r545IpoMMkikmB/3McAaG56VrZucC2AFhJN8xHSvcCce5aDU0 kdMGUJzsigwyY+rtfN2seE6H1bMQFwOB248InKFtDuqb5TAvEqi/l4PGejxwsz8Hwl CHwz7QDQcX+mOs3cme9JFRxThY7U6uqMBO1tMEipxYN4CAgH/WOy+9Tcc2IRhAjSne iXOfKYaNp6gfw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 28 May 2023 18:20:29 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] binfmt: Use struct_size() Date: Sun, 28 May 2023 18:20:24 +0200 Message-Id: <53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E8A241C0015 X-Stat-Signature: oezp1531sduqxwqjrxeq6hp8dpm73d43 X-HE-Tag: 1685290830-881265 X-HE-Meta: U2FsdGVkX1/z775x+ZdczVnzcJAkxImTsShunceuN7gF7P5vf9rTBM5qrvOprzTkjX//Dd+9byGDcxQ23n66M2GVWXJcezwOkKoLuteTzPx5CQXz0cMqrHz6FnRETyuxvoDRoQYYS0K/8M2bHGS5UIUEBQ27L7RB+sNEW8eSiOwn+L3fF7js55SIGTsderUgiNf+EcmyGyOT2fYJFra/+wAN76O9QrYcdWlrZrbEPIu7ozYWP30MfqOK6noB/VmmfCRbBnoshx0ZL1xyN6lTbAIhya+PK8PIIT33WyW92eROCc5WlaSboiFkyP2CiytUuGVE60RDeRskD9ONYslO9j5PQsrA5raabwfwuUYRQSE5eruzVXT+2DVK6TTV9sEkiqvsuO10hd0eDnZlS72J+MV+IoFUGmXykYv6X2QEkM7t2PdDtdWRtvrgxbXUKdBpajFECLL79z+7CDWf0XisMV4gqauFaU7EXKqPgFN4cBoSUm0OdgBVGxkjkA1Sv+xGciJsRShopL3KDs4HEolbZfPIQkOxRRmZ0VRmb18mU2pKrgY1fzRDg6lBFns4HB9VXpEVR1xEfKzqFaUtehUgl53CtVropmOjeUz4rKf/lNbl4YTjocIFDdb4cN71dWRVDtRoJULO4jGUbugS827KYCZv1+++UMOdUbmhrWOO5Gvu9GaQpnwJfC9bMDEljjS3KERSGj9Y7PJAjy0ZHgOQ9tLeY/dC3F8VVFX6QiZ3QZyc5v+1ThP2OzxNbaEcIa1hfjzmUR5aKLKOF/u6ColXW9W3tSJTzAZ+LC59lIISW/8+01raed5bBAwarsQi5f0YvCjpBZ8/fCKgVQqDu3yfgEbUcTL8GKahtIx8vSnpkvjm3A2NtbkUj4WbqRhlPb37qhTK0XxJWCJ7Ck+j5Rayp7JZUEEQXHj7ozQUQQfrx6+erF+YMFHj4wo2cyoULiURYjrNAl7GGVhJqG1SNst 6R4RApjX h0w3Wigx9Rd2G+t/+mMrK3m+TmL09RUEwV3OMeaXTlLrHOsjdGxwSxrUXzJ50kxpq4l8NQhKhtQsemZJvU3/79gbkeBv8M2cN6IiWrcjJ/Mh58bXtCd1UkojeeLhZt6Kc0HLN49TT/SYIYtP1eM0d6AGrhKM25EV8cBC9YDNRf1CRnOeZDgE1ryPU21nouaql6gNcLkN0Kjhl3UUN/riexA35Yi/ZBFWQJKRv 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: Use struct_size() instead of hand-writing it. It is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET Acked-by: "Eric W. Biederman" --- Compile tested on arm --- fs/binfmt_elf_fdpic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index d76ad3d4f676..237ce388d06d 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, struct elf32_phdr *phdr; unsigned long load_addr, stop; unsigned nloads, tmp; - size_t size; int loop, ret; /* allocate a load map table */ @@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, if (nloads == 0) return -ELIBBAD; - size = sizeof(*loadmap) + nloads * sizeof(*seg); - loadmap = kzalloc(size, GFP_KERNEL); + loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL); if (!loadmap) return -ENOMEM; From patchwork Sun May 28 16:20:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13257866 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 0C543C77B7C for ; Sun, 28 May 2023 16:20:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88FBB6B0074; Sun, 28 May 2023 12:20:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83F996B0075; Sun, 28 May 2023 12:20:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7067A6B0078; Sun, 28 May 2023 12:20:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 63BF16B0074 for ; Sun, 28 May 2023 12:20:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 367AB160282 for ; Sun, 28 May 2023 16:20:44 +0000 (UTC) X-FDA: 80840177208.10.053FBE6 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by imf29.hostedemail.com (Postfix) with ESMTP id 4CD29120014 for ; Sun, 28 May 2023 16:20:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=CBwvekAV; dmarc=none; spf=pass (imf29.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685290842; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0xJS/fpIMbVgICwjevG2Mh+kQS4ETIrWvAeZpBHPlyk=; b=f34Tdeu8XAtiaHw2wTsg5cx3j9cA87vMWWVjbQ8wOrcmUJIFO1uB4QQwhco4A6Twj/0g6x lvMW68WJe+6fAx5SoGqpvPCh2obkATRB89rkTE0AIJnAe6XbmhqXuGkAXv8WmdETC2YSHy YvbMQ1sQT6aHJ01RtEZmFf8Ht6TBMi0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=CBwvekAV; dmarc=none; spf=pass (imf29.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685290842; a=rsa-sha256; cv=none; b=WpD/UT99FFGpMYvfuHd95Ngmp4rUiTpr8ttxP2DGYVNTIt/pk6S4/p/VYuRWxAEPH61isf pTnJETVJK6dCfmgRciouRAjDmCjq0MsVCd+8+PkCGeThOCcGgwC70suZf4YXuSkn/lcL4V hCemB8Dz8PjHEXKG65XxVtkc2lHjT9w= Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 3J87qJcsWrDwx3J8KqjZT0; Sun, 28 May 2023 18:20:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685290841; bh=0xJS/fpIMbVgICwjevG2Mh+kQS4ETIrWvAeZpBHPlyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CBwvekAV1qKxJ4DwNqJ9ZDO8acOPtMMg7Q+s4w4fKGbs2vPD7lOV9bOSC4EI2vg4M qWZaaXL7whDH7BvYKkoTs6xIAtYksqhzfEtIUf9gQTRoSoIUVFxoVqHeIEugaQ1U7E CoQ7h2Wo6Fns43siy2gzzdgF5LVRjW+zxjS7t47FmlOloWjca03H6LskQi5vMINkH8 MunknPlfBTPdPZFUEaGKzlaSAA2yJERP3fUHh5Ng9udhrXyXWVqqdJsml+CHZcmst9 vBSXNuRwpT4Lf7pZsMpXtBbKAdlnWBlgkxNaUa5v7Z/10k6HZdHMCrBXXwBg5zYHE1 F6HtkeE+iygIA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 28 May 2023 18:20:41 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Date: Sun, 28 May 2023 18:20:25 +0200 Message-Id: <4f5e4096ad7f17716e924b5bd080e5709fc0b84b.1685290790.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: <53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr> References: <53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4CD29120014 X-Stat-Signature: 3zffm3ktmgcqtsaacqroktwx4opa6qck X-Rspam-User: X-HE-Tag: 1685290842-257259 X-HE-Meta: U2FsdGVkX19j6pzBUP7wsjvWVZRh6v77fBylStGOX+Nnc246bl6T2MhL75D94OGO2Zc6AbuXwokbAYmIAzJdjl2R6kxuVVWqiUdlNhmOiURXdXCWn+4T0mDwmJy0hOvV1Tb0SiDJ4fDL0m8eb+2ZwOKwSuUrK7iFsy0t87RcdwU+DxA0vKWBkX5etVlymZkOk6gdRVthfBO4tfQL6ro4To7YBQLdPumjjXIoWLPxoI+FmWtD8RAsG8xrCzu9soqolgLQ6BcJURwk1Qdr0UGaLK5Z/KkCPTA1vts80WDYJ5UiVNM7G2UBX1Ypx2LrY+xTa3HYBmKtBsFZ2MKAKiWQ1QwPhsmcS6nv+kVZgehQL+e97WO3wkXk+BLZmpGnm3ASyJ1o6TxEg5IQx9HM9CRxpBOc2eFIcg85+TL5rSrmpQuLHCurzlC8i9m5PGnzihD/Cplw5yLkg7asVG+at4esy8yOfvH5LnnRJpS+cRWbkpXSz+Aolj1Vk4yrAMYh8rjX9qXEmrpIcDoDgc7/YRHXp38QZjSvC/98fwfgPj3rzRRtbh7efYhzIRBYJcb+ZWuRm62MjIncQ/Kh+/y2Hzkt2+YSny5Hd//SjnMVSA89G5MZC+EMIZpVqoC21MBQiB/uF2AHjfa+em/z9W8D7MMxQ3gqFVNYiT46+pviL/L0WMomzjbu9lovVBhKS+Eva15HhzaZJ/7zde44sl3fKPQlzqL5Yx+vTTpelY5EAs1Wm/mXGoRuKJYMaYMEbHqUSxfFsrp9FpCPt/S02dg4O4T7v22bAH16jDmOLTP4LaYzUwxaVcOUP6mWliwrMKF7iV85FYsBr6tU2iynDZ9YT8TFs5qfZ1PMJUU92I8Ap286wYkYqubqxp4XPZcWo6SQrk8OfD/V+TljrGDTALRtfWts0R2ALqC1mOOZ7U3mBJ1iYvg/zuw7b1nD79YsThsu62Sc2DlZlQltiC/orYLHNGt efCRJ2pg tWVFmbY8TA8+NqJxseaVsHCTFSIIXwIAnOTVh0gDK0LZYrExBZbZZHKw6Y2TYcWFTAKZrFTVGENqOed3cISRORwuNXp06lk+YAcgdaiQVvcDlGfOt5wte6hgS3T3jxoLBaSZpkjHTDhhFwPbnc/QIsN2fNQcycJyhNw9r5cV/pns6x1ZUxi/PR9eIuaXoY6dKn6OHlb+iKhf4sRL+l2TpVjGbO0W/0F/aqOr6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There is no point in initializing 'load_addr' and 'seg' here, they are both re-written just before being used below. Doing so, 'load_addr' can be moved in the #ifdef CONFIG_MMU section. Signed-off-by: Christophe JAILLET Acked-by: "Eric W. Biederman" --- Compile tested on arm, with and without CONFIG_MMU --- fs/binfmt_elf_fdpic.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 237ce388d06d..1c6c5832af86 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -743,11 +743,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, struct elf32_fdpic_loadmap *loadmap; #ifdef CONFIG_MMU struct elf32_fdpic_loadseg *mseg; + unsigned long load_addr; #endif struct elf32_fdpic_loadseg *seg; struct elf32_phdr *phdr; - unsigned long load_addr, stop; unsigned nloads, tmp; + unsigned long stop; int loop, ret; /* allocate a load map table */ @@ -768,9 +769,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, loadmap->version = ELF32_FDPIC_LOADMAP_VERSION; loadmap->nsegs = nloads; - load_addr = params->load_addr; - seg = loadmap->segs; - /* map the requested LOADs into the memory space */ switch (params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) { case ELF_FDPIC_FLAG_CONSTDISP: