From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B8623F9F28 for ; Fri, 17 Jul 2026 12:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784292343; cv=none; b=T4CXDen5ThDvb4xnTsJcUhL1AcnBizKWZihIrnpgoQQyBnjAPOJr7q61zVWvbEJgs9+v5fRDuMxtenaYe9yEO2N7usNNTZZNtVvrmdZepfcDNhR9D3Ulz73g8YK3oRKbkvuz7vzrJw5UFGSh4Zff/Ups+l4rrs424Wg9Gg0XPc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784292343; c=relaxed/simple; bh=RieLsRVJ1mDAmUp0yKGXNWj7JDhW1POVMFYiCRfMPo4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MXpHQggzSNFG+Jw1h3ykfmmr/l0D+A37bejVo8TtOPLeQYqOu8QzGtvlS02dyUVW2QZn18Z7GpBxSckH14FZ1crVgSuec/S57DQSC1XlMly8x5RdcF9WxVfuKg6WH1ixETgao7hsX2IXByQghjwZsNQtl2t1lW3AnZ20VvMFVaE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T/rN4uVB; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T/rN4uVB" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-47db714766aso776765f8f.0 for ; Fri, 17 Jul 2026 05:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784292339; x=1784897139; darn=lists.linux.dev; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=pidhZMI94NTBLbc5TNcQD1D0S0S0XdPelFHQKt6o2CM=; b=T/rN4uVB4JotuC634fcqGadHwmmQpoH55yKCPvvOu885lGPV8nrrVRo27tYXX9+TwM mD91Jmw1KjqMFeacCxUwPftmA05cqvJOAxQPrN3yUMvoV7QQhbd/OSvpaVLPqikDk8yp N5CqGzPSlOIlVVxD2criJ0rBIojw+NWCT7HIS4XUETOsO0asl+X+f90lGhMskLDKOIB+ MfKC+IXDGc8q9DEicCDjXdXjDK/a2jLXNx4n/BYxg4b3/qYj8/4E74vTeD1ptaaR6PZd pMQw7An0C7yZeHrlpiRrWp0WCSZ7S0ZWQJtzvSY3FTgK4lA1ZOPJlXXfeWKiAAMv/5+b byDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784292339; x=1784897139; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pidhZMI94NTBLbc5TNcQD1D0S0S0XdPelFHQKt6o2CM=; b=PHtfSUrTjgRJyy1w5sJBHzNp3PcXTjNfAT3PIqOrmljppk47qeiLzilpURYf0LILMj jMy8MH4nXdP6iFbjyQm5bzqxdPv++EqEy8CNPTotoh+jfdJXOf1m6XadEwOpl0YSmzOS duKcNtGfNH8XpgV2E0TX+uZb3RWAVMafizWHYZ417LTuDbtlrF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-47f623bc322mr3149483f8f.13.1784292338518; Fri, 17 Jul 2026 05:45:38 -0700 (PDT) Received: from unknown748F3CBA5068 (dynamic-2a02-3100-a56c-5c01-55c4-777b-77ab-69e3.310.pool.telefonica.de. [2a02:3100:a56c:5c01:55c4:777b:77ab:69e3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f63ec7e49sm3499778f8f.19.2026.07.17.05.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 05:45:38 -0700 (PDT) Date: Fri, 17 Jul 2026 14:45:36 +0200 From: Karl Mehltretter To: "Vlastimil Babka (SUSE)" Cc: Harry Yoo , Andrew Morton , Rasmus Villemoes , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Catalin Marinas Subject: Re: [RFC PATCH] slab: don't assume alignment on allocators that may return ZERO_SIZE_PTR Message-ID: References: <20260712120728.96628-1-kmehltretter@gmail.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jul 13, 2026 at 06:53:40PM +0100, Vlastimil Babka (SUSE) wrote: > On 7/13/26 07:18, Harry Yoo wrote: > > > > Bumping ZERO_SIZE_PTR to something smaller than PAGE_SIZE should still > > work: (addr < PAGE_SIZE) check still works, and accessing it still > > causes a fault. No arch should have ARCH_KMALLOC_MINALIGN >= PAGE_SIZE? > > Yeah, I don't see why anything should mind if the value changes to a larger > one, if it's still well below PAGE_SIZE. That should work for the affected architectures. The maximum effective ARCH_KMALLOC_MINALIGN is 128 bytes. It exceeds 16 on 32-bit arm, ARC, non-coherent MIPS and similar configurations (32/64/128). Before commit 9382bc44b5f5 ("arm64: allow kmalloc() caches aligned to the smaller cache_line_size()"), arm64 also used 128 via ARCH_DMA_MINALIGN. Preserve 16 where possible: #define ZERO_SIZE_PTR ((void *)(ARCH_KMALLOC_MINALIGN > 16 ? \ ARCH_KMALLOC_MINALIGN : 16)) with static_assert(ARCH_KMALLOC_MINALIGN <= 128) after the effective definition. This only changes architectures that need it. The max value 128 remains below VFS_PTR_POISON (245) and LIST_POISON1 (256) even before POISON_POINTER_DELTA is added. A fixed value of 128 for all architectures would be problematic: s390 does not need the alignment change, and its lowcore uses address 128. On affected architectures, the current ZERO_OR_NULL_PTR() range check would accept values from 0 up to 128. Exact NULL-or-sentinel comparison may be preferable for hardening. This was discussed in 2016 [1][2]. For a power-of-two sentinel, current GCC and Clang can optimize the comparisons to a mask/test. With exact matching, applying POISON_POINTER_DELTA to ZERO_SIZE_PTR could also be offered as a configurable hardening option. [1] https://lore.kernel.org/all/1479376267-18486-1-git-send-email-mpe@ellerman.id.au/ [2] https://lore.kernel.org/all/alpine.DEB.2.20.1611181146330.26818@east.gentwo.org/ Karl