From patchwork Wed Oct 16 13:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13838464 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 0267CD1AD53 for ; Wed, 16 Oct 2024 13:18:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 890346B0088; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83E986B0089; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72D716B008A; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 547336B0088 for ; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 51EC31A024E for ; Wed, 16 Oct 2024 13:17:59 +0000 (UTC) X-FDA: 82679518782.12.D4882B0 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf06.hostedemail.com (Postfix) with ESMTP id D147E18000A for ; Wed, 16 Oct 2024 13:18:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZGjaNVSU; spf=pass (imf06.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=snovitoll@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=1729084550; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=zJmo7fo/XjYSsNcP8yTWZ7ySwCZoewpYPdmKy0/i4fKnkEcUC+Ia6l7aZdKvObO3oWLoDM U2FJu6+tLeARKk6CW9g+DtdsNDk5xdRR/lhCP+1fyf2te4Sxb7j+hf8faKUG8oG8ejxTXY 3N8kbP494ZWmccm3TEdW5MMo9CxpFHY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729084550; a=rsa-sha256; cv=none; b=Lc1gjhVCbGkkTkewoXwz8cdJwu4EVZ0Va0hrqoKFyCxZuCfpODNUOFUgruT0+3IxqgIyN3 O0Lvg7Zm775UtFlsQr5VlMtze60ImaimnPmqm9iexTat1GjaiyTXZpV4SJYCssJ88mZ77E zbij7s8mvpTsIEqH0HLDJXfvRTBke1g= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZGjaNVSU; spf=pass (imf06.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4311ae6426aso45617565e9.2 for ; Wed, 16 Oct 2024 06:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729084694; x=1729689494; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=ZGjaNVSU1PKhGJsty5dfyQYLuVyer4QhlJzTkhZa8P3nFqMhALcUSbcKqNb5NU9ZSU shN5T1mq7WYg7q3vnqCgImZNzTX53a67kaLvAKEgEzmNoRRb6voh2CkT841vEVstFb3A rwLkTYE0TaQ3mSzm31116efB+8cSeyu3JzJhCdi5j4A6m4Z6T8qmaQhtGHxnIJXtEiWp ATzQxljgujFLYHONvvU2F/eG8ff7V/8gB47FiqLgDf0mbWQj4L9bcWWbJeAqAugdFxfm i0Mkzqy4Fj7sRWlj2mT3ptq2d663HKS7rkrcuKPzv1zyJasR7t8bDvd6+tOvCmMn9/xO aa5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729084694; x=1729689494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=IxbDBKneRbfGFjSZqwpft1MijmwmShCQ8CZN1ZWP7s4lx1JOLY5MCKZ6NWsDEQtLFx S0T2bMq1RJM3kfnZkhZlDgfoY5yLsLzGarbvd7ZUIsTNuJf0uFkhUD92M6sqI9RXJp5t DOmiGklqYdCk7YSKYOHASW7rJftUmjG0MXEqmwZ8traH+ae4dBc50PsT0f+w9W9E8bFN TXv5HIUiHkB1kxV7PNcAJ4jcqZXb+uaNku4zO9j3d1YUIElb/tqHWdtHhNWJo1DVxuhX Dym+DVkVEMdp80WmnLnllW12PvAjfzkYJKf0o0vBKXhn0L5wMDyrBxG/5VFokRt1pkg/ Zleg== X-Forwarded-Encrypted: i=1; AJvYcCUYJGd248jHraP7JYcBpiXvpeAwK/cYfdQzF7wcDNpYpPBT7j19rnSvY/vRRAqTBoKbi37TeCb7rw==@kvack.org X-Gm-Message-State: AOJu0Yy/e8vT8g3MmFeCR51S9HaQcNO131uyna32NEbSSY2WDRu7Sx2r nTafMTQpgq5f3DinXzCFNQ85acy2SMwM/Cm85haAb0B81mRNFpt1 X-Google-Smtp-Source: AGHT+IEPh2uD/e424mZy3TzaSgh1zMe8F8B2stIBFMZzi9dKTninoOvYVP/vLIQdZEOFtDvCeX2T8g== X-Received: by 2002:a05:600c:4514:b0:426:60b8:d8ba with SMTP id 5b1f17b1804b1-4314a362525mr29799615e9.28.1729084693271; Wed, 16 Oct 2024 06:18:13 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4313f5698aesm49612825e9.11.2024.10.16.06.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 06:18:12 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: 2023002089@link.tyut.edu.cn, akpm@linux-foundation.org, alexs@kernel.org, corbet@lwn.net, dvyukov@google.com, elver@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, siyanteng@loongson.cn, snovitoll@gmail.com, vincenzo.frascino@arm.com, workflows@vger.kernel.org Subject: [PATCH v4 1/3] kasan: move checks to do_strncpy_from_user Date: Wed, 16 Oct 2024 18:18:00 +0500 Message-Id: <20241016131802.3115788-2-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131802.3115788-1-snovitoll@gmail.com> References: <20241016131802.3115788-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Stat-Signature: xfkkdr7tkqjg1ogsge4yxwp3ns5g9sot X-Rspamd-Queue-Id: D147E18000A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729084688-650673 X-HE-Meta: U2FsdGVkX18hSCDu6gTSrPpgxl5WdoxSOiBPEPtJF+AUW/Ka8BOVOGv7K8E4x8fqGxGZUKI/9XrAYV4xNYpro48ovFW2A8Nv3DE99jwZbY93WUos3WxcfbChB7tsJHGv3STyd6R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mjrgIwTasjkmt0TtANwYriGptHo16S14NGY8fMvsh4J2zvtqSzUFEKu4h5MP8jJvCfGn/VneLSwKSx4eytr2GpaiA4HyOeLj6XwHjqjiHD2PQUMtN3h9qXHBQlyTw8n2OqzidEj13BNXxkTIOS48kUZ9czyg++ko3YhhP/jkkoaXSoNv8bwk8FB3Xjuk4F6dEk4KmsIcM8CAj3SxynLka4Hjbcp5XiUl+E7BigITe0CiRz71VsxzZzXS6oYV+7SEMmPuPRR3c/vHyxUIRjJmhCRwcsk/1IgIqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000538, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since in the commit 2865baf54077("x86: support user address masking instead of non-speculative conditional") do_strncpy_from_user() is called from multiple places, we should sanitize the kernel *dst memory and size which were done in strncpy_from_user() previously. Fixes: 2865baf54077 ("x86: support user address masking instead of non-speculative conditional") Reviewed-by: Andrey Konovalov Signed-off-by: Sabyrzhan Tasbolatov --- lib/strncpy_from_user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 989a12a6787..6dc234913dd 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -120,6 +120,9 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (unlikely(count <= 0)) return 0; + kasan_check_write(dst, count); + check_object_size(dst, count, false); + if (can_do_masked_user_access()) { long retval; @@ -142,8 +145,6 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (max > count) max = count; - kasan_check_write(dst, count); - check_object_size(dst, count, false); if (user_read_access_begin(src, max)) { retval = do_strncpy_from_user(dst, src, count, max); user_read_access_end();