Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1181902rwi; Thu, 27 Oct 2022 12:17:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Ml8k7aca0Spau75JLrq7XH7l2gxRzDu9v+o3/epThFDNWYDnzGKDdRnerWqnwZ8EpwgH1 X-Received: by 2002:a17:906:7949:b0:7ac:9917:c973 with SMTP id l9-20020a170906794900b007ac9917c973mr13395323ejo.620.1666898252708; Thu, 27 Oct 2022 12:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666898252; cv=none; d=google.com; s=arc-20160816; b=seCkFjyPU6OkPKHuFslAhj/fxSLdzJeuro4oU7AICLzOH1gFS/RypMzLLCJJ4bp6mx T9kRSyEvXTFOsBiZF83oGpAzrwezUQzKXGU4ox8WvK+/LJXigWP2fmxbIDezmAeCW0Tl tOiJV1T2GTJ+Dg4VrdypReCbethtTogt4xUUcLVxwhsm66/P9IRAJ3UzQUX85kUO8UGT 12fhlW+sDmKUqiEGiKeJ4Fo8ecrEBCYgWtu6Y7I/0urLT0X62n4jFWahKuWYLIL1sw7n LJMQBELsxQMcmyfiUYLa1b88C536VUkvO37jAgJTHZalAx/CH568AjuLixJcuJb9Z+Ua i3WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A1XprAgWB0s7wiMtyLLvIEnH2hN1akKHT1cSrZfMn0g=; b=Ix2DN4Iv8nX7X9BOfB4JikWIRlIVUDP9NyOolwJcM5BNF5wY6yN67XeNJGLNHqdczu s0XIwoNidgYZIlCzVO5Vpfu0KuIpHQo7WVTdEciaatcRGUwinQLp8kb91X3d8BVO7xBw vZw0d9ZNS1nyCnHYS34D3dLJYhinM5SyCRQx9JUvxQ3eb06DVncEly+nREWSq50L+fz3 KpC0XBLtrqZxSC0fiKZqSM9OSm5jhQLtx8QrDZkYfrxdUxBOf3XtWzJfTgny3ZgvKk/k QO500csSLC17CslLdI5T3TqFrfBz0EnXiaLXc40ggayQiWCc195NTzNR5PbbP/Yl98Ck wwug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sqz2uDjb; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a056402279100b00462a20f860bsi2401944ede.539.2022.10.27.12.17.01; Thu, 27 Oct 2022 12:17:32 -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=@gmail.com header.s=20210112 header.b=Sqz2uDjb; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236166AbiJ0TGB (ORCPT + 99 others); Thu, 27 Oct 2022 15:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236092AbiJ0TF5 (ORCPT ); Thu, 27 Oct 2022 15:05:57 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25E3E54CBB; Thu, 27 Oct 2022 12:05:57 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id d18-20020a05683025d200b00661c6f1b6a4so1634799otu.1; Thu, 27 Oct 2022 12:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=A1XprAgWB0s7wiMtyLLvIEnH2hN1akKHT1cSrZfMn0g=; b=Sqz2uDjbQlvvJWBpIM/mzfHIsX9oc4U1Fvobpx7j4awZ289LhDdgt28RgrQ7eUUrYb bd/0+diGJAN9IGyFXNpPjroo3xxI7q5obkLaSI9dnXviOhXHyiaC0YPBi3sEikUxPPVL xUdSTHktkBwkoN6/HQ9/REsmPkc4LFqNsw4o5T+4mAZ5LYgDyPs1IJhEL5RxVwgq8DFw bO/aXGKYUNL2Ab3Fq2mfiDB00NJScK6qG5AWF+4LrN2F8fg9zybgp/OMWI/GzYIrPNTg /FL+1zOWNkqqBMHCXP0DrsKWvv92+4659qPZzhbk08RzU1aA1lFOo0kJdjkrhWkMobU5 i02Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A1XprAgWB0s7wiMtyLLvIEnH2hN1akKHT1cSrZfMn0g=; b=E1Y2zvUjsBh2d61ki7j3T8zhLrMCPCukfguVoOWb9jVCNPuk770r/Ln2ir1ok6F8r0 ZddSDcqjwX7p+wzt8spykis2+CFgWvZkbl9KNI8P2hdEqB+msvr4tVExEckv4ukT/ooF tSf0hBJJEffATw7fJUaYyHJSyifEaBt9hAGQiJyd0tZW+3shOoW9GDcc/wEQBS65lV/y swlBPEW4hadIl/oOy0Yl4aumwtEwPpx5lCOb+BtCXCRn8kqo3C38b3q349SiJg/eWh8D 0VEtbI8U6so2VaTUYsy4kwS9Hc2GoMBYAzfpRPhNKvoyEXKvYnaRHotSWfFw47U/MCIp 4xMg== X-Gm-Message-State: ACrzQf1jxtbzRCdwvn1JZXul6Jr+kDhfOuTyZDRQSynJ//IcUepeTTIn LkyFWb87k5k/eEbOdEjQo9zAfOLSyApd0DkW/tE= X-Received: by 2002:a9d:5c02:0:b0:65c:20e6:46a with SMTP id o2-20020a9d5c02000000b0065c20e6046amr23632464otk.213.1666897556488; Thu, 27 Oct 2022 12:05:56 -0700 (PDT) MIME-Version: 1.0 References: <20221022180455.never.023-kees@kernel.org> In-Reply-To: <20221022180455.never.023-kees@kernel.org> From: Andrey Konovalov Date: Thu, 27 Oct 2022 21:05:45 +0200 Message-ID: Subject: Re: [PATCH] mm: Make ksize() a reporting-only function To: Kees Cook Cc: Christoph Lameter , Dmitry Vyukov , Jakub Kicinski , Paolo Abeni , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Ryabinin , Alexander Potapenko , Vincenzo Frascino , linux-mm@kvack.org, kasan-dev@googlegroups.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 Sat, Oct 22, 2022 at 8:08 PM Kees Cook wrote: > > With all "silently resizing" callers of ksize() refactored, remove the > logic in ksize() that would allow it to be used to effectively change > the size of an allocation (bypassing __alloc_size hints, etc). Users > wanting this feature need to either use kmalloc_size_roundup() before an > allocation, or use krealloc() directly. > > For kfree_sensitive(), move the unpoisoning logic inline. Replace the > some of the partially open-coded ksize() in __do_krealloc with ksize() > now that it doesn't perform unpoisoning. > > Adjust the KUnit tests to match the new ksize() behavior. Hi Kees, > -/* Check that ksize() makes the whole object accessible. */ > +/* Check that ksize() does NOT unpoison whole object. */ > static void ksize_unpoisons_memory(struct kunit *test) > { > char *ptr; > @@ -791,15 +791,17 @@ static void ksize_unpoisons_memory(struct kunit *test) > > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > + > real_size = ksize(ptr); > + KUNIT_EXPECT_GT(test, real_size, size); > > OPTIMIZER_HIDE_VAR(ptr); > > /* This access shouldn't trigger a KASAN report. */ > - ptr[size] = 'x'; > + ptr[size - 1] = 'x'; > > /* This one must. */ > - KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size]); > + KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size - 1]); How about also accessing ptr[size] here? It would allow for a more precise checking of the in-object redzone. > > kfree(ptr); > } Thanks!