Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6573887ybi; Wed, 29 May 2019 09:42:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4XjXrU3dKMpeX1TGvNcEP68f+IFwSLvezJgNBPGgzMTVPDhjZx+RFUfAkPDFuD5O4Thxl X-Received: by 2002:a62:e718:: with SMTP id s24mr64703848pfh.247.1559148132995; Wed, 29 May 2019 09:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559148132; cv=none; d=google.com; s=arc-20160816; b=UVQHehpPrrOsi3dxA6C7kpThzRIDFkquMST/Xq47G0UOc5P85DIlYEj9e7bB9She9D QCPzjXcnZjolmD8BXeTOglvKMBLDKl8VuFT+j0jUllWt15aJ4UIgHaTubnFQyDhptKJc z33S0q1+cfZk5iv0G63KNv5gC6QfwO0zi+h9QhzA215/preNkDxszKNJ+VOMKL3hEsGR 6fOlLfUCDl/X90SsAEInNXXZBnQXE/rh3ccDzQN+rF5qneI/BPVLXoCZ/wJUiEgFAiMb +0bRIG7lRzzdykrNyat6nCFbda2TSkFhL/V2dbaaQPrJQ6mfjErhHkBXl2vL/vvs20T5 yhkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+Esfl3nvaEBw2uCWEGOwNd1KcpJR7qnstyVJ5GKtC10=; b=mLnBJSyL+9aO1qcJfv01rhZf5VSdFMT3PXE9WtMzeERdRgqTNFNM60f3htW05+WwRO 9knECFvctCYTtY4JEKkYg+3oeF+YNSEwoQllVpMwDACjZnw0EQKJEiIKH46tWMSWSnV/ yZ5TLakNE9cnvdau6nJ11av1XJEaScot0hJ3tlIO44Sqny5LJJSoKWa4eWmFP2Vll/BF OXNFLG92WzavYBdNzAcB87bSTY3LQphpyREibWf0SEHpMPCqe1iGm7x+GMw+W1jEQzX/ E1/7+eJ5fAyXxyJtU1rGBqgLntWRZZ0sSby43TCLIbEuWH9j8Hhp25k8R/IIF6h7+16U 3Icg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gy54YSWi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s201si103819pgs.522.2019.05.29.09.41.54; Wed, 29 May 2019 09:42:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gy54YSWi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbfE2QkH (ORCPT + 99 others); Wed, 29 May 2019 12:40:07 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:35645 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbfE2QkH (ORCPT ); Wed, 29 May 2019 12:40:07 -0400 Received: by mail-vs1-f67.google.com with SMTP id q13so2343282vso.2 for ; Wed, 29 May 2019 09:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+Esfl3nvaEBw2uCWEGOwNd1KcpJR7qnstyVJ5GKtC10=; b=gy54YSWi28xfcPumIcxdQBpxiv38UYPyQki2rU5FibosdeZ6MlUtt9mGYX3pMzpi1J eVhOA5uX5C/8oMK59ewu0GTbMw/NJWIUQ8b/ZIBDbt98ekfp++OMeCkgUOCvHQqDoN8q DaT+H9TyYWJTCERqolLABJA2fLCqFKB1pboH6qY+GtugTcyXA1u2hJOOP4KVS5o8T1W0 Nc3mxPD+goAx+22GUHKIz3rE9eBxPxsWhYqcyXvXu+t7PAS8w0XKOkNJlFUXgc+fItQU niid+sGwkxSgn5eDnRpH3eTcty2oJDRMsOtoLpYvHkC93a4vKqdqfiIJhAnbRHUedyz6 NvjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+Esfl3nvaEBw2uCWEGOwNd1KcpJR7qnstyVJ5GKtC10=; b=iBKflaAMJrZvbYxujYaNGI4gyFLFItrtTPEj9EmxqIzVW2H9xglagRhoBzJS0awq2V +1Ae0S+ZRq8M3xyvSGTOwSMprJZkdkfqJkLOtOAOZUln//pMM+PgDPsPOoGXRUxhY95R gg1Su+smThxx4AYpCRouFzb82bl2rXxcVtDaIxmpYnSrN8B1SWGZohgn51nGdm9GTmsJ rB0NSCQH8tvVtuK8wtJj3Gb0O+gqgFs5LT4onmExNBTHIIRXdp2IQJwf0zklGWYvasMF D23d8MEeznnOmvnibTh76hQo1Qx7WlloraKW+cgnN/N6evpWMao0ACOIApn2F1GbtwR7 qfIg== X-Gm-Message-State: APjAAAUIxAAqfiOCve5bY1vwlsY0Wha3o9+9ajywRQYNdmBKckfb8OSY gW9KS+1HyxkUcKeKnIK1SvuIH2d6V1a/2D8qx6Q= X-Received: by 2002:a67:ea58:: with SMTP id r24mr5616881vso.60.1559148004894; Wed, 29 May 2019 09:40:04 -0700 (PDT) MIME-Version: 1.0 References: <1559133448-31779-1-git-send-email-dianzhangchen0@gmail.com> <20190529162532.GG18589@dhcp22.suse.cz> In-Reply-To: <20190529162532.GG18589@dhcp22.suse.cz> From: Dianzhang Chen Date: Thu, 30 May 2019 00:39:53 +0800 Message-ID: Subject: Re: [PATCH] mm/slab_common.c: fix possible spectre-v1 in kmalloc_slab() To: Michal Hocko Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, linux-mm@kvack.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's come from `192+1`. The more code fragment is: if (size <= 192) { if (!size) return ZERO_SIZE_PTR; size = array_index_nospec(size, 193); index = size_index[size_index_elem(size)]; } Sine array_index_nospec(index, size) can clamp the index within the range of [0, size), so in order to make the `size<=192`, need to clamp the index in the range of [0, 192+1) . On Thu, May 30, 2019 at 12:25 AM Michal Hocko wrote: > > On Wed 29-05-19 20:37:28, Dianzhang Chen wrote: > [...] > > @@ -1056,6 +1057,7 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) > > if (!size) > > return ZERO_SIZE_PTR; > > > > + size = array_index_nospec(size, 193); > > index = size_index[size_index_elem(size)]; > > What is this 193 magic number? > -- > Michal Hocko > SUSE Labs