Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1183323rwi; Thu, 27 Oct 2022 12:18:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5clL65v49kyMKE2is8DW2V6QUrc+LPYmgMOfvD/41OhFxt7gHrTZSxtYgtwBrhadtQvePt X-Received: by 2002:a17:907:802:b0:781:8017:b2df with SMTP id wv2-20020a170907080200b007818017b2dfmr43499466ejb.606.1666898326503; Thu, 27 Oct 2022 12:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666898326; cv=none; d=google.com; s=arc-20160816; b=b2t4Ok3QbHEh/a9lCtka3yhk/a5IJ32P7dpmbi3MB08f43PGMnR7BtEVzDiDv2/Xqh jAT8KkfcbqgEXgfbjr+vDawhybGaZotLt7hlGMUA74ovUXjJiDNVu5WUoOWYybI3dNix 3kseG24evfr2qcPqRqW+0mrPx5K1WYstukK01dDa56Fpy41nxx318AAz2adkxKO3CcAk n2cX9ncGhGwnS4Ebf4Etu8VCDjGyPeFQ7wrMR7+8MGhinhLiayTWONBM2pOfVPqBKAjo qbGVcO9pjxlEvoCdhp/wV41mq+0h2Ueg1VAhi1BWkF1/JNvd9lsax7mL+1VlCXW0KubD 0i0w== 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=KRy9sqvf0ZM2bZpgrnftqxmIbppdN+rJl6H1sXbtcEA=; b=ZdwF+1fR+MIVf5X/Cv4kHnQ+S47KAo8E2wIQCWgmiWG+hx/SCixTwHbVDXbxAHHTGw 5pCEKHOiGUF4n6Fj1mokJjkEVZtf4MEwJcB4+RRT79LYyOOcdj4ZStJl+UmKa9FQRhGs HbLlZbo2xdPRsx+Tme6Oos2RVuBU24W6FgXnPsN9FQ0u4P1g7HHIq6CUtj8tfwdtDh4V kp2U43UhzxdbN1eOngC9AN2IaE0/q9EI8JjCfL3vwO1CAhwfoRqoyPD5d4lOdP8DHyid heA3bT352nlFN6nYkCZde9QIegwJoPbqZAYQRUjQ4WogWP4NfIsG6Yx3Nc2rLaGt31+I UUhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ePBvbYsq; 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 l21-20020a170906795500b0079fe11e92ddsi350344ejo.906.2022.10.27.12.18.20; Thu, 27 Oct 2022 12:18:46 -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=ePBvbYsq; 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 S235744AbiJ0TNZ (ORCPT + 99 others); Thu, 27 Oct 2022 15:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiJ0TNX (ORCPT ); Thu, 27 Oct 2022 15:13:23 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C439870E49 for ; Thu, 27 Oct 2022 12:13:22 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id e4so2604714pfl.2 for ; Thu, 27 Oct 2022 12:13:22 -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=KRy9sqvf0ZM2bZpgrnftqxmIbppdN+rJl6H1sXbtcEA=; b=ePBvbYsqqxinV1869tyLVSPuexY7f5oFCO4bFBrZ0zRyJ8fAIYv6HyDImZpOI7sDK4 wV01b3ApWa7HxYPZmSq7Y80QJ8waTqfMmGkATXW/AodfcPzYcSL2X9iXgY+1T73b5Ysl 7tELmVPx85ac64Og2sYczqg5VmOjiPDZGHsIc= 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=KRy9sqvf0ZM2bZpgrnftqxmIbppdN+rJl6H1sXbtcEA=; b=x0HMh0doaMPVD5JweKS+kmF3VFTawb8Cdu6Ii8ojBkCLHRU8ixbIE+O78AQe3fkqdZ HLvS9TBE7Ajn/sGxy2/9CRx0aezhI7jEA7uB0fiYxoKcDz/5Fe/+Vqx9EXe/mU/aQXpo dUuet7CxyWatt/LT8DJElJxQ6G/Ukcboo39OGZqC6tZYCDvPFw6M+xcfXBYx26q5qpMr skfPrFsJjoiKlqtf+AANHt4azslKljBAMRgcy+lzCpgBpOFzIsqkObgPGzLit2dsI5mE O9wfgxMBP/uhS2P1dswJlwFmhTyGEmemolQITdV9HabdVXea8LhH42AeZW+elsvNC5Kd lS0w== X-Gm-Message-State: ACrzQf28ttOPM6ytFTvGSdSNzFsYwzfxvd/jMFaAsocgbLktBjw7yV/L EM1mNt8HBSqWtXJEPhFyJ/ibQQ== X-Received: by 2002:a63:7909:0:b0:458:1ba6:ec80 with SMTP id u9-20020a637909000000b004581ba6ec80mr44062420pgc.414.1666898002301; Thu, 27 Oct 2022 12:13:22 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q10-20020a170903204a00b00176e6f553efsm1525222pla.84.2022.10.27.12.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 12:13:21 -0700 (PDT) Date: Thu, 27 Oct 2022 12:13:20 -0700 From: Kees Cook To: Andrey Konovalov 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 Subject: Re: [PATCH] mm: Make ksize() a reporting-only function Message-ID: <202210271212.EB69EF1@keescook> References: <20221022180455.never.023-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.6 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 Thu, Oct 27, 2022 at 09:05:45PM +0200, Andrey Konovalov wrote: > On Sat, Oct 22, 2022 at 8:08 PM Kees Cook wrote: > [...] > > -/* 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. Sure! Probably both ptr[size] and ptr[real_size -1], yes? -- Kees Cook