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 E9AF4C282EC for ; Fri, 7 Mar 2025 01:10:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2A8E28000A; Thu, 6 Mar 2025 20:10:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E01C6280001; Thu, 6 Mar 2025 20:10:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA0F528000A; Thu, 6 Mar 2025 20:10:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AD999280001 for ; Thu, 6 Mar 2025 20:10:51 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E968214012C for ; Fri, 7 Mar 2025 01:10:53 +0000 (UTC) X-FDA: 83192975586.30.B0E6032 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf09.hostedemail.com (Postfix) with ESMTP id 0E90C14000C for ; Fri, 7 Mar 2025 01:10:51 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WX9jmOAo; spf=pass (imf09.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741309852; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U8W4lBndXbHt9de0ee6upN787KMW52umATu2vsi2G1s=; b=lXQDxgpM/YATbnzUIQXsl8i9YXJhMUjsKMtq5yeeEC67XYZj01G/vJ9oDfVNndtmKWJ4T0 wAidX0YodZhebNEKtBkYRhH/xz9xqpRigYmXSsk1VXWV2wDa6JFj6nUY9YwoqQOmOR6Bzq Ongb7Q6/lvca9yWX0vFDpZmTyqCGfag= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741309852; a=rsa-sha256; cv=none; b=x1N0SVnvoONVpfMmRzBrPxiPTCLdRktuvNaRTKU3rkt6uQt4VhweRBXoB+9nzpDIxTc/ub tSn17yQe4WiAzXFjKitFssMlK50Y+E6yxB1jf7vzB+6aYNx7J/RHJ1sYFwNBXYM8oV2PQx /YVhcECNIrSaVe16rFy6COguc+cahCA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WX9jmOAo; spf=pass (imf09.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4394036c0efso7514775e9.2 for ; Thu, 06 Mar 2025 17:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741309850; x=1741914650; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=U8W4lBndXbHt9de0ee6upN787KMW52umATu2vsi2G1s=; b=WX9jmOAocTbRIE2pn1XJsbwjheldhs1c3Lhlx36fbPjKPTapiKPOvapk56TwjkJ1Ng v1h/3q6jYm9IUBpmLlAkt3EhlwAp6gafIw+4LsULj7dRxQp6O13YSIXpliSNIbDkaFgh I0t46nnZtLeM2yQVMTxuvbe+e8hmNxd1MPkSUaIkp57reKenGGZZgNXSgjOHwxbWLd1K PA1PUx4VvKFE5Wu82lPNtFc36Dewt9dTdcr4u8qO56kcLo+ieTUmau2HS4i/UaSYmR7r j3uAphUoXoaTHeg8qUipsDuqsT5l8WOLE5UKZFDw5zJZedU9IF2qI0XTwAElos6aK3QV haxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741309850; x=1741914650; h=content-transfer-encoding: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=U8W4lBndXbHt9de0ee6upN787KMW52umATu2vsi2G1s=; b=uMKpMhM5prt36yZ5TTCBhCxm4+Hm6tL2Loems9Q2AsbLIlyt3fg+6nIrgcpImOza5l nRUWI4Tk0HRvy76PM0E2BJi1JG/irCtgDiiomZA9ZqdgPHGSqLnX4breliZd8MIHjwYc ppiO8dClPTAxh9BpBDepmHdG5dPx2MPmiifKHc448Ge4hjgY9IhKm4hKvzL827/U85xv OiVTCGId4WooZzVC3nJ/9au23MP9Kr92TUI98wWppQNgxJQf+VToCCG/99xzMKhTI3nk 4x5cHCw8u3ZgyU7uxKB+3i2v3A1fmtdFN220cMeTxvcrDqi55cTjLei+Aq+DKjp7vTNe CY8g== X-Forwarded-Encrypted: i=1; AJvYcCWHuOnMoKltg9sfe0/zK0tsCbio/gSrwtOXLG0++SqytfT+1dJt2iUknQWh2paLYY8EDqY6wkZtmA==@kvack.org X-Gm-Message-State: AOJu0YyV28h5mb09ZLJqT1PfB4lL2SJXg/z9bSAYvsvVEZ9U8sgb+Z6B ehsYxarqgkhJGcyCZlmUqMxzSSIAxG/yzeUqjvEvJGF+I90wTLnngQ6tFrrs3GMkAPTFMIcNHpf MCSgTIy4pdaYtWbDl2218VU7Ulxs= X-Gm-Gg: ASbGncvsskjS4ygUzp83a312NOET+37QG6JHHYAIfrtFQJ+krBmWkTY2RlicUnYoYkL u0w6Pel1lCnQWm89ZEtEAM+XjcH3YmpYqiYBVrgYEnWy6OqBbyGpEZnpTHtsXJTGr6ZS8hvaVKj Kxm4gyppZB1vjbCywPNvc/RlXyTSYk X-Google-Smtp-Source: AGHT+IHcxwy2elEu5fwV9PGx1saik9Pw4IRZRUb5LxTYzJmaYAjPccFT/W64mJXJreBTFyx+w0ryjVybFCrO+CIEJ/Y= X-Received: by 2002:a05:600c:6d8e:b0:43b:cc3c:60ca with SMTP id 5b1f17b1804b1-43c5a631736mr8352965e9.21.1741309850252; Thu, 06 Mar 2025 17:10:50 -0800 (PST) MIME-Version: 1.0 References: <6wdzi5lszeaycdfjjowrbsnniks35zhatavknktskslwop5fne@uv5wzotu4ri4> In-Reply-To: From: Andrey Konovalov Date: Fri, 7 Mar 2025 02:10:39 +0100 X-Gm-Features: AQ5f1JovwqbYdeSGr0-fcudbS7_ChDFAODKKUUmrprBtHFAHDoFjM50Rrc6n6VI Message-ID: Subject: Re: [PATCH v2 01/14] kasan: sw_tags: Use arithmetic shift for shadow computation To: Maciej Wieczor-Retman Cc: Vitaly Buka , kees@kernel.org, julian.stecklina@cyberus-technology.de, kevinloughlin@google.com, peterz@infradead.org, tglx@linutronix.de, justinstitt@google.com, catalin.marinas@arm.com, wangkefeng.wang@huawei.com, bhe@redhat.com, ryabinin.a.a@gmail.com, kirill.shutemov@linux.intel.com, will@kernel.org, ardb@kernel.org, jason.andryuk@amd.com, dave.hansen@linux.intel.com, pasha.tatashin@soleen.com, guoweikang.kernel@gmail.com, dwmw@amazon.co.uk, mark.rutland@arm.com, broonie@kernel.org, apopple@nvidia.com, bp@alien8.de, rppt@kernel.org, kaleshsingh@google.com, richard.weiyang@gmail.com, luto@kernel.org, glider@google.com, pankaj.gupta@amd.com, pawan.kumar.gupta@linux.intel.com, kuan-ying.lee@canonical.com, tony.luck@intel.com, tj@kernel.org, jgross@suse.com, dvyukov@google.com, baohua@kernel.org, samuel.holland@sifive.com, dennis@kernel.org, akpm@linux-foundation.org, thomas.weissschuh@linutronix.de, surenb@google.com, kbingham@kernel.org, ankita@nvidia.com, nathan@kernel.org, ziy@nvidia.com, xin@zytor.com, rafael.j.wysocki@intel.com, andriy.shevchenko@linux.intel.com, cl@linux.com, jhubbard@nvidia.com, hpa@zytor.com, scott@os.amperecomputing.com, david@redhat.com, jan.kiszka@siemens.com, vincenzo.frascino@arm.com, corbet@lwn.net, maz@kernel.org, mingo@redhat.com, arnd@arndb.de, ytcoode@gmail.com, xur@google.com, morbo@google.com, thiago.bauermann@linaro.org, linux-doc@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam02 X-Stat-Signature: pswiom3irx5see7dhxp8oztnfwd6jtkz X-Rspamd-Queue-Id: 0E90C14000C X-Rspam-User: X-HE-Tag: 1741309851-166149 X-HE-Meta: U2FsdGVkX1/R8t0DeqvFCmAJE9OtKjlq81qpyK1eRTo0gBPURc+OiKHnFwwLtcw7jk5wBGt3z5/UE7TPWSu7AtHu+SbA665NBrhjf8OiKRJUoYujlWqEDSeNlssDsGylM8McrmqEwCb0XKruvnARRmnaTKfZ0pNKhgFqJpGs16VLiQ8bTUgGWbQENX3jeh0CmvyDLs3aAep1Vgy+7hndPRPJ78A+/jEVPWFABgHS51vkfGxu3FBtRIu2Opf4ElcgCd9TGByj9to71kZj73TxLuqaXHuhfjFiux603K3K6sZsaqOOeSom0G3jmVz+UVjPAGf8F4Lj0YhN/qBWmBM2Oasa3Uso4FZyDy9Lsg3Y5KPj2vjP/YnRgQNDan4FxYSxHS+cJOonGPZQebLkuk4shJdniTg0AXj8QQDRL227vUa/AV29Fupi1PG0/UJ0uoWNloNFfpbnA9LVKAML2KMA1sxjyDZsaK4TSiu2oGgVxfYHCgdRtk1AGLW0HowsP2dbJdbL5Q4jLdWpPjAkPB2h6MnbKNy6mAzBJlFA8TKGYV2EE4WBG1GWbL9cEWe8aXS/AtJM7qyGro81MTDVsl1+kRQZAbeMP1OpDbRC7mcdtKGGsOK4wlTC3fdw0vfJyGZURfo4/MJ0ELAxDeqhnKWsiP8ReFNSopGJRArRaR6QG87+tTK7ra3e44P0dh2dpCrJ9J4XloNEW5KU4jtTp+1luro3q7y0uSkY7KIEt8xfyeQkeZroXLDaQm6yVtEIS0GpohAdpF5jyq8TSZ5Hi5nZO7PrHEuMf0/iNYL+71FtzE+UJRzRoFbrQ6GMlqmMk34xxl2hYdqeplWU7uXXGkmYIPjAZnuJeipgfdG3oIvTY/0s4X8YXfcXtaS+pyocHmUHxyvRhE5WG9VsS+71ydhRAD5x0ZjmPaBeAgJi7St//9Wn/Bv6LCl8Zqzkk8rEayW7v0hsYSvNbzYEt/OPiB/ yL9a3m1X WZGtKVUKDQEHG5jXC4yYfIVXgbtzPdLpJK0PrISMEfQI2AFo4abN+31FPVSc3jv5anevLlRqvl/g0q3sAAN3qHRTeMkcdDaNl/T9h/Wr0evoQOtSt4eWz1qApmpGPL9+CwOgUTDEjgcM0MpcYFqVEa84nLOdC1g3JFbz7C0CEZlDokvxSp5iFZKWCxbCaMgDs2Or/hzxyM/ys8nkkQL4xM7myXov8gczeQfY1iBAobsmqVBIK+GXqjL+E0cAodOBL/1sSu9AK0G7dCh08B5wR+YEU5CNQIajN1NXlBxy+S+gu4pogECFP6oJziH6Y6Ab0oatftlURp6cNOrg4KFmjYB31GMp9CHF1AgDfifV0geraYsiUU3lec/XXOoSRKSSh+r1NFqfRCJQI/Y/32OfFnRIkD/+j4VOFAqGBmlncWfAZpGSaH6QsuhWXzCQux3lhNuSckuqWwnhtuhE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Mar 4, 2025 at 3:08=E2=80=AFPM Maciej Wieczor-Retman wrote: > > But looking at the patch you sent I'm wondering - are we treating the ari= thmetic > in kasan_mem_to_shadow() as unsigned? The shift is signed (arithmetic). But for the addition, it doesn't matter? Adding an integer to a void* pointer should result in the same value, regardless of whether the integer is signed or unsigned. > You wrote that all the ranges will > overflow but I thought we're interpreting the arithmetic as signed - so o= nly > positive addresses will overflow and negative addresses (with bit 63 set)= will > only be more negative thus not causing an overflow. Ah, yes, I see what you mean. From the C point of view, calculating the shadow address for a pointer with bit 63 set can be interpreted as subtracting from KASAN_SHADOW_OFFSET, and there's no overflow. But on the assembly level, the compiler should generate the add instruction, and the addition will overflow in both cases. The important thing is that both possible shadow memory ranges are contiguous (either both start and end overflow or none of them). So this was my brain converting things to assembly. Feel free to reword/clarify the comments. > That was my assumption when > writing the previous checks - we need to check below the overflown range,= above > the negative (not overflown) range, and between the two. It could be that your checks are equivalent to mine. What I did was to check that the address lies outside of both contiguous regions, which makes the checks symmetrical and IMO easier to follow.