Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp377385rwi; Wed, 2 Nov 2022 13:03:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UNbfhRdSfmJ61s/a3jEXdAMis/8z2VsWk7s00B/7cBbXffQX4gV+kLYSsV+vmUVLaKOKs X-Received: by 2002:a17:902:7c97:b0:17f:5abf:9450 with SMTP id y23-20020a1709027c9700b0017f5abf9450mr25813863pll.19.1667419386801; Wed, 02 Nov 2022 13:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667419386; cv=none; d=google.com; s=arc-20160816; b=RQEga3WXdT8TEZfm3VrwcD9hEBpf1Beb5vnqp4XNj5rHWHh1mmuW/ZZhEGOjuL3CN3 12m9RYVOq9Wp/QDP9kNmJ1PysEljRi0fIMPLp38BpUiHZqdjbgWpXo7HALTKm2Ceu7hr ZeJFErXmDJiUHR0p4aPO8bcRxng5Z1u5LB19VFWY+qTrw3sk332cSzX4B6O5irZcuWWL jxfZ/lt+8cH9nKG5G7zmHso+9FGVxl4yB+UOYlD6iX9JyfdwxA19pWTeO/1hFfydfeX/ 57E4+r8NmvqmYU+pRqLYtJaJlq1w5Vw1xMScGJCqAopxSaBNLpng4BpCXBYl2eNA5sBS 5W1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eB2CkIIW+FvN/Lo/L+v4C4FsoNsh4QvCTpwzE0gzBz4=; b=a3QdnvCes1320HMeaunD+0s4E+g2DWPayG1dvm/gkw2VcR/G/eLeyNLfCK2rn5zNEM qclIoSIIQ5U9K6DTnoye0K94R5NNByLHxrN9dSO4yW7Er+cXmTN9YEKnjtvXmnAA174r h3mNXuQ3YI9PvMZZu9KDyyr3Y8tIrEkAYh4ZG2yi+Lu6kZyqobIN+UVo08txZN/pi4CA RFnOZmv7XyNAxs/pipUB7E4s60VyZ+fda2CMfhffRcbKNFmClfZG3SU7v0eb0m0zEPoN EOuFDpmTrEHqq8McvPZa5fj0F3C+Ra/5RmYkz5aqg2sKPxGCQO/5Y5LuftGsyh7lTZ+c qukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kopbiQPK; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb17-20020a17090b281100b0021305ca5933si3436411pjb.42.2022.11.02.13.02.49; Wed, 02 Nov 2022 13:03:06 -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=@chromium.org header.s=google header.b=kopbiQPK; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbiKBTki (ORCPT + 98 others); Wed, 2 Nov 2022 15:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiKBTkg (ORCPT ); Wed, 2 Nov 2022 15:40:36 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CDA11170 for ; Wed, 2 Nov 2022 12:40:33 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id io19so17555755plb.8 for ; Wed, 02 Nov 2022 12:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=eB2CkIIW+FvN/Lo/L+v4C4FsoNsh4QvCTpwzE0gzBz4=; b=kopbiQPKWrumIeCuEELANKVvXKnGRiVq/vRKpUKLVafnmidHI5pNYouJ+JNTPAt/v4 MguZEdCgIejN1AFkopf4SKhqQEoqmBgfllHic7LKiJoSRRNGE4nCyQkJ0bFpfskjlGls LLl88AjgS80QOIl4RVeYl/lqzdPgMw4C3Vdn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eB2CkIIW+FvN/Lo/L+v4C4FsoNsh4QvCTpwzE0gzBz4=; b=QSwJ6zyF8TRT/aboO8eWvyKngM800oM6k1XRJ5lZRI3afHZ3R59Ub/XGkME6h8QKOz 70bPnfSGSUylnXtVQKj8swBL38F4EiPhYb3viQ3Y79tb6O7zQiE8HfXuBZE68pgFMofA kWM7oLuxpztbTHK300KGmnDm+oe0Qwh0O0h0CmohnHlOIh0p1k5yOk9HwqUf63iGi57o b1NmNMI2mANYlooSgS/7J9oj4V8XEJQPolEvqwDp9rZ5ydRyJ2yLwDJjiQByyt726NWA Awxj9XvrSy9KaMRLaM/9SZES9XS9wr7DCHopHpi5rDL4bSv851XClPTbPUxyu0JqOIMP uy8g== X-Gm-Message-State: ACrzQf0Oec8cZCVyaKK+Que+PooSkg+yxn4PkwdaESj/7fLDdDyU8iKI 3UDK1aZIvDknobU4Sfp9KBRvHg== X-Received: by 2002:a17:90b:2305:b0:213:7a2f:aed8 with SMTP id mt5-20020a17090b230500b002137a2faed8mr27732037pjb.129.1667418032775; Wed, 02 Nov 2022 12:40:32 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id iq1-20020a17090afb4100b002135de3013fsm1805607pjb.32.2022.11.02.12.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 12:40:32 -0700 (PDT) Date: Wed, 2 Nov 2022 12:40:31 -0700 From: Kees Cook To: Rasmus Villemoes Cc: Vlastimil Babka , Guenter Roeck , Andy Shevchenko , Paolo Abeni , Geert Uytterhoeven , David Gow , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH 4/6] string: Add __realloc_size hint to kmemdup() Message-ID: <202211021240.4A97FDE0@keescook> References: <20221101222520.never.109-kees@kernel.org> <20221101223321.1326815-4-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Wed, Nov 02, 2022 at 10:26:40AM +0100, Rasmus Villemoes wrote: > On 01/11/2022 23.33, Kees Cook wrote: > > Add __realloc_size() hint to kmemdup() so the compiler can reason about > > the length of the returned buffer. (These must not use __alloc_size, > > since those include __malloc which says the contents aren't defined[1]). > > > > [1] https://lore.kernel.org/linux-hardening/d199c2af-06af-8a50-a6a1-00eefa0b67b4@prevas.dk/ > > > > > extern char *kstrndup(const char *s, size_t len, gfp_t gfp); > > -extern void *kmemdup(const void *src, size_t len, gfp_t gfp) __alloc_size(2); > > +extern void *kmemdup(const void *src, size_t len, gfp_t gfp) __realloc_size(2); > > What tree is this based on? I see that kmemdup() has grown that bogus > __alloc_size in next-20221101, but in next-20221102 this commit seems to > DTRT, namely > > -extern void *kmemdup(const void *src, size_t len, gfp_t gfp); > +extern void *kmemdup(const void *src, size_t len, gfp_t gfp) > __realloc_size(2); > > (i.e. there should never be an intermediate commit where kmemdup has > __alloc_size()). Right -- I fixed in in my -next tree to not use __alloc_size. -- Kees Cook