From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDA87FA3743 for ; Thu, 27 Oct 2022 19:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235464AbiJ0TN0 (ORCPT ); Thu, 27 Oct 2022 15:13:26 -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-Google-Smtp-Source: AMsMyM4innxfNZAzhGWL/DpqnIwUOYEYiApzjV6DBWLPdx0UZXtA4mdOwut8gE2N2aGulndGyPlvSA== 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: 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