From patchwork Mon Oct 14 02:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13834113 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 13BDCCF259F for ; Mon, 14 Oct 2024 02:56:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 953D46B008C; Sun, 13 Oct 2024 22:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 904CD6B0092; Sun, 13 Oct 2024 22:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 756976B0093; Sun, 13 Oct 2024 22:56:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 55D0B6B008C for ; Sun, 13 Oct 2024 22:56:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1FFC11A0AA9 for ; Mon, 14 Oct 2024 02:55:56 +0000 (UTC) X-FDA: 82670693490.05.B170372 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 0F1B84000C for ; Mon, 14 Oct 2024 02:55:58 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jN6tcdsY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=snovitoll@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728874452; a=rsa-sha256; cv=none; b=va1K7q5ukpQ1VyH1kpHJ8L366MyCE/RXwaH9IxiYjv+YdbQyc7mMz2ovE/TLoBzNCcW4MY xyz87dH73WoUz3Wb0nU62UHUze5ZPIXDX9rO7u58LI6duSKESxj3c/wuTQ7+jbgpyDFAai 8svKRYuDalxnRcDKonIGcxplBTryzf0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jN6tcdsY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=snovitoll@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728874452; 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=fsia9jopa1EBGuIlree1T5OAe+wj8zghwoJWVSExaNA=; b=LcIooYC/kzsEFaBGCSfAEMulsEHuw+ZbgNPvzJywFPSRRiDnoV4AZo2hW+96SLQx+bJWKP ibkblDy2nloiWtjnvcCxuqugGf6oHpOLNdEYJ744Rs3fm+gDPTE/OK8sJMsmyRqqMEQV0X Of/I0NY0Xy7g8NlRSWWbXOyJth+f7no= Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5c9709c9b0cso1285848a12.1 for ; Sun, 13 Oct 2024 19:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728874565; x=1729479365; 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=fsia9jopa1EBGuIlree1T5OAe+wj8zghwoJWVSExaNA=; b=jN6tcdsY2kFWO/1X5ctLyjlNfTqFUTnTcstp88h0g2up+xxc+8U568UiCleakvtDPd +QJ767MDeQuFDNR8ScHZTlcyTsa0BdtD2xf3YXGq7mLNl7dyiSATvac/7GonTj8op4qK ajc03FTAeidy7Mpoc2FufgIH6FrXKFIbXhv0KP3EpHQgMBKFBsa1NarQM2BvgdXg6oMm F2CVywZFXvcKZ1oy61B5fFOqehRzxwPHCso8u/bv6vDqKvGl952+ecauXmGqYNR/lf1y j5UwCsGe4kvkQbvr0ke8ZIMFfAinjTZFUnX1aOmHZwZReml12dfvjma7is2Pv6PsMo9P mDGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728874565; x=1729479365; 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=fsia9jopa1EBGuIlree1T5OAe+wj8zghwoJWVSExaNA=; b=P7luPOyXLQCX5mzcMLTqbLzZgxpRee1JclzxMuNUV22UYAaIZVWW+1RYEAHV1HT/z5 LzrUn/iAfxKevhckl0L341Cqx2TshNfTd0s/SKCxH0+lmPF4zPOMKuYyWRCy1AfCvoa4 If4LC1a/pJaoAXww25OhYB+W9M+VfhrWLbFICGwn8AF7O5K4Sv9RavkfY+4T5gbn19CS rRjMVSfbcgsDxDpkgCJ2b/VbPgJhwljxeh96N2HBykFaz3g2NCnwO7UtSx8mHxE9xSKn +64zk2vWB1gbDFBabJzkNwZ3c8pjU5LAPN+nzeNzOclZG3f4RMIRIqwO0lJ3iEwLMATT YZow== X-Forwarded-Encrypted: i=1; AJvYcCVPIiwxJYBFoCt2vNcUpqThtNECB0A3/xzCJmLXM3YHJEbj55XlKtF2wPXqzKD2E+JJq7mqvqD+8A==@kvack.org X-Gm-Message-State: AOJu0Yzfi4kcAOeWKetwhUkx5p5538MPKwVRvJCCLlQupQ3OhPrYxNMh C0K69fkfnRQ37OAUZtxnvHTJdcjor7diQQBPjGQsqpr9NvaqiZ3d X-Google-Smtp-Source: AGHT+IGnwwZeigphOJ9brMGXGLoktj1FJV8WBeBfj1WroyrEnTp3w3CdGAC9gyG0bLeuTFdMUZwEGA== X-Received: by 2002:a17:906:6a12:b0:a99:742c:5c7 with SMTP id a640c23a62f3a-a99b9305ed1mr791073066b.10.1728874565516; Sun, 13 Oct 2024 19:56:05 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99ebdfbff1sm270501366b.39.2024.10.13.19.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 19:56:05 -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 RESEND v3 1/3] kasan: move checks to do_strncpy_from_user Date: Mon, 14 Oct 2024 07:56:59 +0500 Message-Id: <20241014025701.3096253-2-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014025701.3096253-1-snovitoll@gmail.com> References: <20241014025701.3096253-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0F1B84000C X-Stat-Signature: d91o7kbgjjm7jehqwzn8qz5emxffjiin X-Rspam-User: X-HE-Tag: 1728874558-699505 X-HE-Meta: U2FsdGVkX19CpvqSP7u4082QkTnmdmk1ocbQTzzp7GUTXmywz76nPI8xyoqPPfGxjZvXkxQZ9YrPgLn51pvfeuYOi64kPuddiz+pz/2/pSv5O6kCw6DoSOBMNUVAuF4yJVizmO037suXg8ONS0vXePFCLkfuZrN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yDzmcTmxnhG7Soxl9Jp40Qxy5OjBxtkhZ854nZxIsuhd5b7nT/63TVPk7L8m79MgdwXAZYtfnwA7Ko5mYf20lf5uIshsQS9SskJVelkFSOpIG3w67zu4/K//PxQNVolgFOQ9FsT6D0iXdXhCEfR70mkyltqfK1l7fQieELchdMdt/r9hhNqxW9q9Gu6UsVXQfgcBTQ/UIDUB6/l9xElCLFog7oweS1kjqyDegYgEB7k1B7rHRDE23M/RA5J0wMZrT5gWw== 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: 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..f36ad821176 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -31,6 +31,9 @@ static __always_inline long do_strncpy_from_user(char *dst, const char __user *s const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; unsigned long res = 0; + kasan_check_write(dst, count); + check_object_size(dst, count, false); + if (IS_UNALIGNED(src, dst)) goto byte_at_a_time; @@ -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();