From patchwork Tue Feb 28 09:35:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13154614 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 096DDC64EC7 for ; Tue, 28 Feb 2023 09:36:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BF8B6B0071; Tue, 28 Feb 2023 04:36:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56E686B0072; Tue, 28 Feb 2023 04:36:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40EF86B0073; Tue, 28 Feb 2023 04:36:11 -0500 (EST) 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 3371E6B0071 for ; Tue, 28 Feb 2023 04:36:11 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05C4CC140B for ; Tue, 28 Feb 2023 09:36:11 +0000 (UTC) X-FDA: 80516194542.12.4D42F6F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf20.hostedemail.com (Postfix) with ESMTP id 0C9B51C0018 for ; Tue, 28 Feb 2023 09:36:08 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sRYmU6Y+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=8pKw1F7i; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677576969; 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=taaLiLGPxaqufQ2R430/cnXrJjAKnDyXV614KjX4P38=; b=dlc7KVQoehrsSvAj1pS1phigN3ZBL6T+msyFkq6FqNw7LMfvAkH5q8K3IS9uTwlR+4RIvH vGSwrYSkWrDXA7BfsxeMxRJlxpL8z/RlUOXESNNuTCBZ53i23KHjLm7mYV8e6iUiCwdC+G JFyWg4zIVm6/Fdrk9ZgQMEWeJ3Z4wWg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sRYmU6Y+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=8pKw1F7i; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677576969; a=rsa-sha256; cv=none; b=z5JiQCfin3dLm83P53h0kT3BXKyk7uggMXROR+2D9YIwEw+B/wdIlbMIvtTPP5RvPDW/Ks 4PyebX6Vwf2b88lkIFn+uLUXL8KasvvE+dtyMQ07xxwaRKC8ykOvuwEjU51sc89dpBdPCH nV8W6Bm6PwT7aT/GiTSX4BLK2YP9kWc= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 48BE71FDC2; Tue, 28 Feb 2023 09:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677576967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=taaLiLGPxaqufQ2R430/cnXrJjAKnDyXV614KjX4P38=; b=sRYmU6Y+9Zjnuojqw1yyR1C1Xp+9gqic7ETrAJ3f22NJo30oigfnbYDwhbX0i9t2VjZoiO sW2uWwZ7QfeFSPg9axfWslKerdOqD5BZAFjkeRhprGry1Hbpts70WHkSdwvXa6I0suORvg NemgZnzptyk33aeqDm6EmH8/Q88KE/0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677576967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=taaLiLGPxaqufQ2R430/cnXrJjAKnDyXV614KjX4P38=; b=8pKw1F7iyYH/ijfXTkoUdIAp9bjuwkUcZT407zpqJ4gKz/BMDqpCi53C+jNZm/ueHSUeNr oiwzzXLaHnb/VTDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 21EE91333C; Tue, 28 Feb 2023 09:36:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mMCXBwfL/WNzOAAAMHmgww (envelope-from ); Tue, 28 Feb 2023 09:36:07 +0000 From: Vlastimil Babka To: Kentaro Takeda , Tetsuo Handa Cc: Paul Moore , James Morris , "Serge E . Hallyn" , Kees Cook , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka Subject: [PATCH] tomoyo: replace tomoyo_round2() with kmalloc_size_roundup() Date: Tue, 28 Feb 2023 10:35:56 +0100 Message-Id: <20230228093556.19027-1-vbabka@suse.cz> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0C9B51C0018 X-Stat-Signature: 5tth5so4etf98rx81b8cnd38c6imk45b X-HE-Tag: 1677576968-145410 X-HE-Meta: U2FsdGVkX1/3f+1+MCTeHEa4LbWyPpFeQUys/nMXsX6/GWUStJYTPQVsjHqwbRUDQydq8fOzKaPnp2tOip7ZaHa4rwa/c0+TNL1RyeYrdQTKqoLcJd7rPaek7kdLNBj4k/AiZ5YPu0k7ZSoMbcsWvENzgB01laZ1AdJKEeokmKiWTj1WGhnVBBlR60p7LWYq7EgAXv39v1SkR1Xbnx0j9LllNdT84ocYz9sQBJPYbwX2qFqESKxvuojpq1d6oyiC5yYKbUwd/9FHZR7Fyg806KMcjpHQ/m2wMt/8I6luyzk5QpTPyNO1KHi7TLvXbBgEjMY6a8jmnpX2TCWpKR/a+VHeTmTZZeot1OUo/dKCTEArrC+Q6kJYOYBw1YDGbmkRPdHUqOIfNZPlrj2kK76NAhiibB6HdJ73lhs8EBUqBMaF5iYbcGhoBf9zEOrivIbQvAjPCnOH/1CNg9XJKUYYBL6Y1/nu1yFIDKbzc9G7+weL2zEbiBmZm40VTgoAZOz395U3oazBjCP+qL/GTQHuEmwL0CpXrajB6UAEEf8WcTlhQx+elspqplwOLjrDSEcGpTjuHcuIaTv0tM6qaFmEy4OoMc/glVpDpuCPhJrLWNII9h2vNNvCsFgz2ikLlm2R1CoqBdviDLHGSdFKjqYlXv7JXy7Kk3ET/qi+uHCJMMXt7KSDrPHuIbyBk+2vRPDCBA3UwPT3EcSd6ufvPICKBVlUa2dM97RRK1HmE1A4OMWjmtshAqwX4M94nX3hUUMqrATv112ZrsYWBUv/kr06ZkF1Jc+xGLt5Oi/FAYqFqTJNYnyaAGQswJwgoGYijgAeN/tkuKEeBXxfwu6O3YeJ7ImUcg6rsCWfMS6Tt1yN3y+MUkJac1mrup9KCqmddrEd/Dx2boM4oOtz/kdgGlcffra94BioHMGwUSm+FJmaGP65/HLwJXisxVMIMTLZ3lwz1okBufgoa5Kq0k4Sr1j j692FMUh +pZJCFEqAUiAi+vwoEnELu7P1Mi6AfMdJpRuv4DBeTKPgleNv2DfUYVCpc6ARXp4PNY7hGu6uTnOzD1hK9MFgyrB0kLlvrtq+/km9GEP0QA6a7t9ZdxROjzK3LLvDZp0dFtjm95dleiOuhauOqPDY0h1ghjXcmprn3l7+kUAIN1OCX84PJSARVMmsyFEP1qS2c1JeKysJ91irFACaDYkN+6NBmyXtBbzA7WZzqq59FixT0wgAKWPGF5DcAg== 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 seems tomoyo has had its own implementation of what kmalloc_size_roundup() does today. Remove the function tomoyo_round2() and replace it with kmalloc_size_roundup(). It provides more accurate results and doesn't contain a while loop. Signed-off-by: Vlastimil Babka --- security/tomoyo/audit.c | 6 +++--- security/tomoyo/common.c | 2 +- security/tomoyo/common.h | 44 ---------------------------------------- 3 files changed, 4 insertions(+), 48 deletions(-) diff --git a/security/tomoyo/audit.c b/security/tomoyo/audit.c index 7cf8fdbb29bf..610c1536cf70 100644 --- a/security/tomoyo/audit.c +++ b/security/tomoyo/audit.c @@ -271,7 +271,7 @@ char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, /* +18 is for " symlink.target=\"%s\"" */ len += 18 + strlen(symlink); } - len = tomoyo_round2(len); + len = kmalloc_size_roundup(len); buf = kzalloc(len, GFP_NOFS); if (!buf) goto out; @@ -382,12 +382,12 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, goto out; } entry->log = buf; - len = tomoyo_round2(strlen(buf) + 1); + len = kmalloc_size_roundup(strlen(buf) + 1); /* * The entry->size is used for memory quota checks. * Don't go beyond strlen(entry->log). */ - entry->size = len + tomoyo_round2(sizeof(*entry)); + entry->size = len + kmalloc_size_roundup(sizeof(*entry)); spin_lock(&tomoyo_log_lock); if (tomoyo_memory_quota[TOMOYO_MEMORY_AUDIT] && tomoyo_memory_used[TOMOYO_MEMORY_AUDIT] + entry->size >= diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index f4cd9b58b205..969d4aa6fd55 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c @@ -2094,7 +2094,7 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) tomoyo_add_entry(r->domain, entry.query); goto out; } - len = tomoyo_round2(entry.query_len); + len = kmalloc_size_roundup(entry.query_len); entry.domain = r->domain; spin_lock(&tomoyo_query_list_lock); if (tomoyo_memory_quota[TOMOYO_MEMORY_QUERY] && diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h index ca285f362705..a539b2cbb5c4 100644 --- a/security/tomoyo/common.h +++ b/security/tomoyo/common.h @@ -1276,50 +1276,6 @@ static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void) return tomoyo_domain()->ns; } -#if defined(CONFIG_SLOB) - -/** - * tomoyo_round2 - Round up to power of 2 for calculating memory usage. - * - * @size: Size to be rounded up. - * - * Returns @size. - * - * Since SLOB does not round up, this function simply returns @size. - */ -static inline int tomoyo_round2(size_t size) -{ - return size; -} - -#else - -/** - * tomoyo_round2 - Round up to power of 2 for calculating memory usage. - * - * @size: Size to be rounded up. - * - * Returns rounded size. - * - * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of - * (e.g.) 128 bytes. - */ -static inline int tomoyo_round2(size_t size) -{ -#if PAGE_SIZE == 4096 - size_t bsize = 32; -#else - size_t bsize = 64; -#endif - if (!size) - return 0; - while (size > bsize) - bsize <<= 1; - return bsize; -} - -#endif - /** * list_for_each_cookie - iterate over a list with cookie. * @pos: the &struct list_head to use as a loop cursor.