Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1185453rwi; Thu, 27 Oct 2022 12:20:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wezstbE50ZPIL6eRoBAadaPWJEKA1ta5Ycr9Etj8H0FAnZrqKIk4AVhFL8wUDivB06CNu X-Received: by 2002:a05:6402:2710:b0:45c:d7b4:6948 with SMTP id y16-20020a056402271000b0045cd7b46948mr46984943edd.215.1666898426018; Thu, 27 Oct 2022 12:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666898426; cv=none; d=google.com; s=arc-20160816; b=FxqohpmQPP0+ychnla6bOnVYT32blhpP4YZ24SzVykSykJI28JVkpV4w0FJD7tx5z6 bFtIlSWCl/JwrYS37cGycvSW2urCsjyrij6WFMA7zy+skmhzHVhlPgor0YihOlKE6k33 hbDLKUJlc7CGPV7i56pWSAvRKQxsxu8YA5+7wE4qQD63uuyfX1YvYI7yDj2zUlHB2+ar bYPlque81rtdW94jTMnNfmMCY7e/63sQ7iXsqdVYACgmZ/bDrm2j6UvxlQJ8NAW1+1sq v3qXWEYSjohd7ddp72ks8LKE+AayoJexavYWO5extC/sy4/U32EM7Gab1VTMqtIs0n7/ tQLw== 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=eCsVCuaf2go92u0eYyN6AvJOsvbg6jhQcYiOWielii4=; b=pkcvHs0iXZlM7mfkxXZiIHqQamlx08OyGTNoqhQ6XrXMN8+6csQE6cqGoZYVhJbyzf PtZVktzacLovIIXFecM/9yJcrJpZ8WGlk4454BWAB0+luDfMkWbADoxDpDFjrTMgSLT1 8y5623ZB2MiP9npD+Aw6fum+FWGV5LYn/p10GOeqcP/0tggNo+8eudfrcbwQDeInpfOG 3XjjYICgt/oJgvuLc1hdWQtW30paCmssdefH3vYsCjCjsYWKZ4DsANPCy+YLeHHdyDPA 0tcvjZuOnYtP09ayp1jlWYHoouOgeI7yBwkqJ7xPiG9B48VblPw5SgK1hm8nA++bhWVJ 39Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R0iWBH+H; 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.20.00; Thu, 27 Oct 2022 12:20:26 -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=R0iWBH+H; 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 S236004AbiJ0TQJ (ORCPT + 99 others); Thu, 27 Oct 2022 15:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236103AbiJ0TQH (ORCPT ); Thu, 27 Oct 2022 15:16:07 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD305A836; Thu, 27 Oct 2022 12:16:06 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-13bd19c3b68so3473497fac.7; Thu, 27 Oct 2022 12:16:06 -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=eCsVCuaf2go92u0eYyN6AvJOsvbg6jhQcYiOWielii4=; b=R0iWBH+HPjJ0SQdZ84Mt4uYE+Bta4bVdd1ncs9eqbfofJpPePa6XG9quwkgAuVwy0n kB2rMYQldd1ASFbzPIjghjc19QKB+Vk6xcyLhtzYrIMNQvXD/77YpqD6RoZjUUukcCjm xyG49dB/CLPB1z4W2WwNKBt6boRPtkSTiCNdFuWGWGhenpBeV96nMIUFmI73pjcLv/Jv 34hU2DEiJa/Qrg6SRcSoXY5w+BZ8/Ug3vUoSbZDO+2POPYkVhIUs5WxTbDTjTP1plMb7 6JGV1JLbFGJFK6kgHRaaYBhxkbbXAKZTB2A8hq1M5BY6EOHWSfHJp1LalMvxbEM4cPTM LKEQ== 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=eCsVCuaf2go92u0eYyN6AvJOsvbg6jhQcYiOWielii4=; b=o6IXg7inFIaaF9M96y4uu8GRbLK9NXULWGPL1gGvfo/gTqV05mCuX7vdVdXuDOYh0D tH0VxJDtvoi2hF6WtikfC1mfvpGBZigeUUqBKUxAlyAvBfqj7sDZyRFoAEqI4WbHGUiK 9PVLH0tKGtH9sYgcPn+n5wjtsknEKCbZn4oFuNWpaWhpCl8fg30UDVi2dYieYFI5Pep9 vrWiP0K1XvB3RyRxktH9gdMccktwyW8iTUeQzllK9q6vKWt/ryx1Sowio2FwwU6mXkTh uQhF78ck5vHMyVv74WlSf/VGskUBMXDYu1A8enzsDuDMyUS6KtjErWTm+DphIOAmjK/f d2TA== X-Gm-Message-State: ACrzQf10eYL24FxQ7eGzxddEjx1slsdUBT7yVc0QRvo1veGYeoNlo5CA lgpnDlqeTkjwgG4gBXB/H9ZzZRjKzmEzVmrYz1w= X-Received: by 2002:a05:6870:c182:b0:12a:e54e:c6e8 with SMTP id h2-20020a056870c18200b0012ae54ec6e8mr6423090oad.207.1666898165661; Thu, 27 Oct 2022 12:16:05 -0700 (PDT) MIME-Version: 1.0 References: <20221022180455.never.023-kees@kernel.org> <202210271212.EB69EF1@keescook> In-Reply-To: <202210271212.EB69EF1@keescook> From: Andrey Konovalov Date: Thu, 27 Oct 2022 21:15:54 +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 Thu, Oct 27, 2022 at 9:13 PM Kees Cook wrote: > > 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? Yes, sounds good. Thank you!