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: 99910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1041585vqr; Sun, 28 May 2023 09:26:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rCzOC8HvHiRjORH7bTLKSkmjxCb1DJhUrG0J3uff0FsIeBFkJmUoIa6lRPPvSTrDZEFjW X-Received: by 2002:a05:6a20:3955:b0:10f:243c:a6e7 with SMTP id r21-20020a056a20395500b0010f243ca6e7mr7255463pzg.13.1685291208949; Sun, 28 May 2023 09:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685291208; cv=none; d=google.com; s=arc-20160816; b=WtIrGVDyl0ejLcR0QJ1id6R8j1ukPyz8QJchq2QH/x5iacRTUVXxMiamf8WRRkuX4W zwx/gO2Y9dumRCOdhfXbDsPZhpTdOblWuEHv2bqxcH8aUFCKo5Xn3QYctiVitBot6D5t EGpMoPLC6poSEw84FLjS3yhu8XQ7pxkxwpVQsPUCGfp4BE8iv8HYM6hcBW1Oir5KY+b7 2SSaePuaXp7jF7cVUdyb9f5eJRlyTmN5hKhv0TsEu3rHdeb6st8nDbgJ6782vyHyy9UT HvM3QizdA3t8DYwGH841Nq9xgL6ulOGYs33Av8Cb70VA+wbey3qTXHMR9LowF7vdMC0k iwkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; b=XmXR3zb0+E8yaaSRZyXpqLFhijhciexab0JR2OcoufBk2ksHj4tpMYvI4BmUJZz5sr hWPiLROIMN4mpgfaRC0xK0UsSrxbX4HRN8ttjN0HMa04nK+YF/B6wA59h827crPm8aOt 4n6LKowS+PmT+kTYkzm6VnJjyekTeWUUnpqx3w3I8jeqwPx5p9AObjLcq/U1Tb5QM2bH L0U7yv7YesB2bzN0YrMuFQBoqs4jtDmD6OMstltr3KhmOdMPUYYCU09+2V2GMbG6qA09 wI88WeLHzLHJrT6rxfp1S1L/MH+HLWQ4pFEDMZjUFuDvfglHzTmdY5gxU2akMpeVX7Nt kCwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a633f05000000b0053f3e6ec82bsi6596754pga.774.2023.05.28.09.26.36; Sun, 28 May 2023 09:26:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjE1QUe (ORCPT + 99 others); Sun, 28 May 2023 12:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjE1QUc (ORCPT ); Sun, 28 May 2023 12:20:32 -0400 Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ECC3BD for ; Sun, 28 May 2023 09:20:31 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767155914506282779?= X-GMAIL-MSGID: =?utf-8?q?1767155914506282779?= 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: 99911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1042682vqr; Sun, 28 May 2023 09:29:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bv7FG8aBDQM8IzWpOn3GbWn/C8y6KUCyilgrtoQIcGzc9gExsROCBMRMiWJKImjAfSCXV X-Received: by 2002:a05:6a00:2d94:b0:63f:1eb3:824b with SMTP id fb20-20020a056a002d9400b0063f1eb3824bmr12608184pfb.17.1685291367653; Sun, 28 May 2023 09:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685291367; cv=none; d=google.com; s=arc-20160816; b=Ypkg6Ne94sGVATRlftbIP0pBtB0ObAEntf2ccJD1oDp9eBLrxggNLBETeZATB44uym QzpIiiwiIXLQ36kSPip6fqs0ti4mON3Y8YerwxZqIU2c1gXzllbcvowjjBEGzFf2JZz8 iIZwBUiezxJVwArh9oMfDXhi22TkCa0KYlTPGVFyj5qCUNvQeYJub8h7vaPAEzBWgAm3 oBTlUByDybyxlk9VMPqGM355R/mxtTsibz+dwMpI51lCqgHwX1gIxJiVyd1iqC1HssKy uYryaI3JJn5O19sRUZ0TeUOrArEfnSRYJpTWJWaqJjStA/en5A74h37emFZ4+FsYFzoe 5TJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0xJS/fpIMbVgICwjevG2Mh+kQS4ETIrWvAeZpBHPlyk=; b=u4p5TdJ44PwV5AH2NNH7Ib21ab9zuFpKjkmh1rhMXG1fAAsm8IzZe3875FMpQ5FblK 7XIekqIJ0d/9retOsIU1s3Mbd0zj7up1Gn7j7M3qj84q/NMgR9zSVaQ14BbpRBHIg/nj e0Ru/zLesPBgD7o2z4kc0jKqMlk6Rwwi91IhYjUrusUbfDbYfKqg7hI7QWOkJZgxiRGE dVzzjCdR7eoSoTj3wH24JyZFBYJbSkTb09fKI5Dk4PgBEaGxdhXLsvVQYY+d1lP5ohzI NZaxbnINCjX0u1rS0p8aMhsNvhQ7v5W3QbLc3p+AY0fLjKA2A+SwcZu89kwPVNgLOlzh wpyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=CBwvekAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l188-20020a6225c5000000b0064d35b65bddsi6257328pfl.362.2023.05.28.09.29.15; Sun, 28 May 2023 09:29:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=CBwvekAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbjE1QUp (ORCPT + 99 others); Sun, 28 May 2023 12:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjE1QUn (ORCPT ); Sun, 28 May 2023 12:20:43 -0400 Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C785BD for ; Sun, 28 May 2023 09:20:42 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767156081170318869?= X-GMAIL-MSGID: =?utf-8?q?1767156081170318869?= 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: