Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1761174rwd; Tue, 13 Jun 2023 13:55:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6M8zHwIoSgs0t2oY4KIU+sBOCxllYjGDJFSijekoP1dXWYXONsILhfJYtGFATpSxiOAatO X-Received: by 2002:aa7:d04d:0:b0:514:ab84:b72e with SMTP id n13-20020aa7d04d000000b00514ab84b72emr8511836edo.18.1686689746070; Tue, 13 Jun 2023 13:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686689746; cv=none; d=google.com; s=arc-20160816; b=W/HQQXXwwgNIdSQDTB/wzALZ6YsGdikLdG/KGswk84wxW4wQbtKl4obQg2bwfAD9BN uK+bRGrUwJGfetKkqqAtMzpTmHZQvRRp0hMHTMSm6E7Vwjf7ske+ifNyJkF1Qp+6Rqn1 fhcHkiLcKLPYpVEJWQ9bLVUqWEOnlSOuuyXGzdEDG/rJzUpAnsNCxBHfyNwQW2wI9iyG eODwicNSq1J4IKWqyTBl1RM6mtsbLS6GyGG8+oREEWgYQ5COQxofi3CDo6Kys7rBugGF m7ESTr4bB3BARxYTimtE1vn6hgAQKgo2wX+i/l2h3FDTJuzLRHA6wjXpmIQ5zNO8AIUR aRbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=P33YgGs6OZIxngy95+ozg40+5//7kMaRyYq7qJmuQ0Y=; b=S3ZMdrybJea5TYUk2FRd0dMFNk0S+LQwLhomFZB+eI7Jnkaa0FZ29xfM7bi+IKHt40 MleGx/hKcgSs38Sv0/xSHM/atFW0dlS9H9OtAWdWALVyrnp+fCTF3lhQAxgsjCMEtvff d3OyLBZOGzOPEjSq/gcYVFjR+GsxH3+DTlahZFFrGda/ncOYpGytWg7L/iuKRRvVVvrP zoddRjaROJkcpbGgOuEvh0hbOy1NoIq+ZqT2WNisuRLVnLaSH+Me86CNGDWWRl5W2u7v H22pcRniu13AXhBQJYIpnfDoA73iIJFSkj0v6sp+SRcZAZfnQBaUoHGCBCieHmZGIVCT P4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=V19y85sg; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="nHa/66Y+"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020aa7de08000000b00510b6b9aa11si7791302edv.459.2023.06.13.13.55.20; Tue, 13 Jun 2023 13:55:45 -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=@ryhl.io header.s=fm2 header.b=V19y85sg; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="nHa/66Y+"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239441AbjFMUi3 (ORCPT + 99 others); Tue, 13 Jun 2023 16:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239495AbjFMUi0 (ORCPT ); Tue, 13 Jun 2023 16:38:26 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6074D1BD3; Tue, 13 Jun 2023 13:38:23 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 045EB5C01DD; Tue, 13 Jun 2023 16:38:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 13 Jun 2023 16:38:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1686688700; x=1686775100; bh=P33YgGs6OZIxngy95+ozg40+5//7kMaRyYq 7qJmuQ0Y=; b=V19y85sgevW88E/PFN9v/F1+YVpGMdvbUVD0n3A9QLbv/t4ggdx fw7Ln3P72JE0ABvWtQuBS2R6YlQA4Eq70QIT5LqZmBuHpjby4OmeMhiCtkozpOEJ isgjJY/lh34zvEpBV1Z4/CW5cp3EDYA/HZdxzXF9VYQA+wofHiRCgYgJQ54zvmwR SeNkBNm/7ZR4/4B8UF5Ki8R3sDVwdd1mlvGhEb6LX8lChxzw0/Jh1DQxBLvGEZc/ CfBrVfJLlQLH91C76fal51snoPUVJNtanOKUhUKvLxe62hFgO+IkhW5m0AMNAVfD LVjdljcDWfml2BKaRQI1/2luAPugXAb2trg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1686688700; x=1686775100; bh=P33YgGs6OZIxngy95+ozg40+5//7kMaRyYq 7qJmuQ0Y=; b=nHa/66Y+wkQDCh0Wtfo2//OBIhTgEOcWP/DmmAx7S4hQKyJoVdt KCO/wG9lGDo7SkZ2TOSfeIgesthOvTogycHk+ZN1Hg2hWyparr8Rsmzj9ih+a9r0 FdkN3ZeFMaUcCgXjdJTGH6zZH7DdRQUdQ4qtTxSm/447fUQKPzvoLN/XqsSLL1YL 0WetCgimt5guRex/vPx+jQ9pV5aT9J243GAdUsHziUGrs5u1mvxx24kAt0ZuGPGI 2kW3mq4RBBP2mHw7D2LmaBZj6Nq8yrNFW3enGA3Z4ureMSrt6fVvgJiMb8+nyDPi 07h02Q9Sn1DY0vEvDxP8O96KJ5cLeKctTaQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedujedgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomheptehl ihgtvgcutfihhhhluceorghlihgtvgesrhihhhhlrdhioheqnecuggftrfgrthhtvghrnh epheduuddvteekvdektdduledugfffhfdugeejgeeuvdevtdetveejheehiefffeegnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlihgtvg esrhihhhhlrdhioh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Jun 2023 16:38:14 -0400 (EDT) Message-ID: Date: Tue, 13 Jun 2023 22:38:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH] rust: allocator: Prevents mis-aligned allocation Content-Language: en-US-large To: Boqun Feng , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , Benno Lossin , Martin Rodriguez Reboredo , Alice Ryhl , Dariusz Sosnowski , Geoffrey Thomas , Fox Chen , John Baublitz , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Kees Cook , Andreas Hindborg , stable@vger.kernel.org References: <20230613164258.3831917-1-boqun.feng@gmail.com> From: Alice Ryhl In-Reply-To: <20230613164258.3831917-1-boqun.feng@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On 6/13/23 18:42, Boqun Feng wrote: > Currently the KernelAllocator simply passes the size of the type Layout > to krealloc(), and in theory the alignment requirement from the type > Layout may be larger than the guarantee provided by SLAB, which means > the allocated object is mis-aligned. > > Fixes this by adjusting the allocation size to the nearest power of two, > which SLAB always guarantees a size-aligned allocation. And because Rust > guarantees that original size must be a multiple of alignment and the > alignment must be a power of two, then the alignment requirement is > satisfied. > > Suggested-by: Vlastimil Babka > Co-developed-by: Andreas Hindborg (Samsung) > Signed-off-by: Andreas Hindborg (Samsung) > Signed-off-by: Boqun Feng > Cc: stable@vger.kernel.org # v6.1+ Reviewed-by: Alice Ryhl