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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D03C0ECAAA1 for ; Thu, 27 Oct 2022 19:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 026776B0071; Thu, 27 Oct 2022 15:05:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F18A06B0073; Thu, 27 Oct 2022 15:05:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE09A6B0074; Thu, 27 Oct 2022 15:05:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D0A876B0071 for ; Thu, 27 Oct 2022 15:05:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9621640D59 for ; Thu, 27 Oct 2022 19:05:57 +0000 (UTC) X-FDA: 80067659154.02.A9D0933 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by imf12.hostedemail.com (Postfix) with ESMTP id 436934003A for ; Thu, 27 Oct 2022 19:05:57 +0000 (UTC) Received: by mail-ot1-f44.google.com with SMTP id 46-20020a9d0631000000b00666823da25fso1651036otn.0 for ; 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=mYPGHVMM0TQ00SaxzdIqSv1w4UfeRac3ojfm94Vnm1IIGH/J+fvPS5HpjfPaCBKm7R 9AJqKBoxkpj++xgkPoiXtv7U7EU/JauyKHWnyGj/xo1h73CRpa9Pf9Xg3Ok5VB/1KjMO Ec5E34pKU9yI/cUZvAV0qSUBdWoNepS3WUmhJFhbnTSG4eJ9fs8A00ALJcAFRDTJEPiu giTM5BNb67N38VHaPxlMvRN/lsDwY2Co3n2lg5q2hmeVfzRgiruuEsmVMFV1BF8BUEzG B/RlZH3GurxpjBZuDly42CaaRt5Dm8bptmX29uO4WxmZQbmZF3Lvt8Q6Y3FoXpwsdaF8 YJBw== X-Gm-Message-State: ACrzQf099dATInETFyvO+No8TZJpFtw99rCGP2p1/hnKqCXvbDp3u/D/ /PK1gZsnwaWEriOKlzYWwpMCbJyZRiHFJlYbtaw= X-Google-Smtp-Source: AMsMyM62sEmSG5aCY0b4YK8+TARwW55i4i3cprSqu9DEfEpzzWfueCTetYFLRwjOVkDhkr+y6lZqaDEu+nmEdLaT55w= 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" ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Sqz2uDjb; spf=pass (imf12.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.210.44 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666897557; a=rsa-sha256; cv=none; b=x9fkVD8SXCDdW3J4Pq8ctObM+Xflmx36dsnyTDojI6KAckPdglYMbMBBCskudUAkhHlFIZ pVPrf1upBQFm82cnBhRQsx/XxVfz1ngkOEQ4KiL0tb08dVsng0kFKg4vhTFqYsKzxvNae/ WsJQ8ZY/fYbfALPITF7BVw7VVwQAUnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666897557; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A1XprAgWB0s7wiMtyLLvIEnH2hN1akKHT1cSrZfMn0g=; b=fFiGNO4L7DVsk0gpFe9eSdySbjhJrtnB3dy8PQtTFr3OqCAFB25hs3PP9B4mFbWrxHkX1G aIWWBjPKHq6SjFgBLkxQNxcLpHDx8mu7SjDhm9HKqECKoc8nHAaqUs7XQ6zgnzYgVFXWl4 fuZhn2KUSYwolmxO5yYf5wcmPhdCe2g= X-Rspam-User: X-Rspamd-Queue-Id: 436934003A Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Sqz2uDjb; spf=pass (imf12.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.210.44 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: mcqfoebqb7aksgz67kkf8upeicgkq1js X-Rspamd-Server: rspam10 X-HE-Tag: 1666897557-412802 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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!