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 03F38C47088 for ; Thu, 1 Dec 2022 16:51:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C7EC6B0071; Thu, 1 Dec 2022 11:51:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 278236B0072; Thu, 1 Dec 2022 11:51:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13FCE6B0073; Thu, 1 Dec 2022 11:51:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 03B976B0071 for ; Thu, 1 Dec 2022 11:51:29 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 902EA1412FE for ; Thu, 1 Dec 2022 16:51:29 +0000 (UTC) X-FDA: 80194328298.17.E733A19 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf19.hostedemail.com (Postfix) with ESMTP id 286931A0012 for ; Thu, 1 Dec 2022 16:51:28 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id v3so2160982pgh.4 for ; Thu, 01 Dec 2022 08:51:28 -0800 (PST) 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=frCt6pKGWIhEPpxLesPSV/Mh3cTSx4zBWHAWHmqSudQ=; b=DwwmIVJCxrknnFgsAtQfghmeg6nsCZ8RoEEzEVvPbBI+wiM0sY1ZbxrczIzURz/60h G8+ccZ3zqtKCwPp2UrvRxEqizKfqh6SQv4BeP2xqCrHbJk9Y4Sz6MxKuuG404UkEWsv7 8oV4Q0b0J53QS6xITTCYCcyqbBzo42atOFmjE= 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=frCt6pKGWIhEPpxLesPSV/Mh3cTSx4zBWHAWHmqSudQ=; b=0ze4DI4SBRH9U7D6FliwOn+GJVkEGIhfi4AtEn2NS8ZtXISr2HrQIeSwa4pJ8ij+1a ZNZyEoCMwzqo5e5h67xUW1K5mFspPoQ0bPJ0XvIgs7rMufCazibq1QnYrlWROKZoEZrO fy3L1prbI58InC1KgtGbRntJWCVt1HmFG6L/BMYcvBxq53LXI7NHBrkvhb+Cb8ZIwST6 FvhuxOUFS6g+SJ8B9rSeq7w3hI4y2EnTHbb3MaKwUjWmaayS86/iktsMO2BHyfww3M/7 KSBX2lq2DQhGHHqvliYjO9w8SeneQ96gDmvqFdZ2bbtw4fyQAnQsgCogldj9CSNBO0G6 8dig== X-Gm-Message-State: ANoB5plfvmFTUDUw/X4fpn2DKvkJ1JHJS0YjhvVG8STxg/8cDozJWn8u PfgRSIH4JrRSlocPJB/i2r0+eg== X-Google-Smtp-Source: AA0mqf7SQT+A6xpC5K3KTNxK3qiYLvhaoNq+xncGf94HScz3Qcx2ku1px8PEYfDLlOXelx/lEs/iXQ== X-Received: by 2002:a63:5262:0:b0:477:6e5d:4e44 with SMTP id s34-20020a635262000000b004776e5d4e44mr44707636pgl.7.1669913487993; Thu, 01 Dec 2022 08:51:27 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 13-20020a170902c24d00b001745662d568sm3844626plg.278.2022.12.01.08.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 08:51:27 -0800 (PST) Date: Thu, 1 Dec 2022 08:51:26 -0800 From: Kees Cook To: Andrey Konovalov Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vincenzo Frascino , linux-mm@kvack.org, kasan-dev@googlegroups.com, Vlastimil Babka , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] mm: Make ksize() a reporting-only function Message-ID: <202212010851.33009FA7@keescook> References: <20221118035656.gonna.698-kees@kernel.org> <202211261654.5F276B51B@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669913489; a=rsa-sha256; cv=none; b=lomCVNqOWy2xED/rEtk6pXGoZ1lpjck2t6ACmUqY2EesuNV+CyY96+KtVtXs56bEy1dHZA IQczFekLTiLwR966A7YsXIC2yV0atYeB4w7XR1KmONA9wlS4uK+PiHK6+roOoW8tdnw3Nr DLamXbnUcx+iOheLUra09hk9sYvcdIg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DwwmIVJC; spf=pass (imf19.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669913489; 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=frCt6pKGWIhEPpxLesPSV/Mh3cTSx4zBWHAWHmqSudQ=; b=gJuAkzNAwQxTRoL2brcpEE3dH0Sj6z7oOH09xW0xv7AqtnoiI5Z7d5RRaaDHGeIaMIwuo/ cF26nepyr0/rlBQ3I4XlS7mASRX96be44B4DmVqXmP7N6CeYEiwkWuUA4XDS3rm4Fg1emE ZAqUvlu6KoSD0skq6eF86sazjUinc6s= X-Stat-Signature: wb5ou8usjg6h6fu7mqj4wreo6tr1ju7a Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DwwmIVJC; spf=pass (imf19.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 286931A0012 X-Rspam-User: X-HE-Tag: 1669913488-629598 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000064, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 30, 2022 at 03:11:35PM +0100, Andrey Konovalov wrote: > On Sun, Nov 27, 2022 at 1:55 AM Kees Cook wrote: > > > > > I just realized there's an issue here with the tag-based modes, as > > > they align the unpoisoned area to 16 bytes. > > > > > > One solution would be to change the allocation size to 128 - > > > KASAN_GRANULE_SIZE - 5, the same way kmalloc_oob_right test does it, > > > so that the last 16-byte granule won't get unpoisoned for the > > > tag-based modes. And then check that the ptr[size] access fails only > > > for the Generic mode. > > > > Ah! Good point. Are you able to send a patch? I suspect you know exactly > > what to change; it might take me a bit longer to double-check all of > > those details. > > Let's do it like this: > > size_t size = 128 - KASAN_GRANULE_SIZE - 5, real_size. > > ... > > /* These must trigger a KASAN report. */ > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) > KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); > KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size + 5]); > KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size - 1]); Done, and tested! Thanks :) -- Kees Cook