From patchwork Sun Oct 13 13:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13833404 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 93F29CF2579 for ; Sun, 13 Oct 2024 13:01:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A7B66B0085; Sun, 13 Oct 2024 09:01:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 157EE6B0088; Sun, 13 Oct 2024 09:01:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3A656B0089; Sun, 13 Oct 2024 09:01:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D287F6B0085 for ; Sun, 13 Oct 2024 09:01:58 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0F5C2AB030 for ; Sun, 13 Oct 2024 13:01:45 +0000 (UTC) X-FDA: 82668591390.21.8C71C67 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf26.hostedemail.com (Postfix) with ESMTP id BA3F314001D for ; Sun, 13 Oct 2024 13:01:52 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ApU1kxd3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=snovitoll@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728824401; a=rsa-sha256; cv=none; b=DekumQo2cREmMhHRHLp1RK5jaIBkMortTe9ievmncf7V1YU8qTBTuFUCpuvIFzABzKsBDz RMeh33nMxjSSiz1g++tRx/oxSPdMdto3+wXKIPprliTowJHaQbRrhFiByBL76x6n63HQds PGS5UsdNLltqzF3G2F/dna98Th90UNM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ApU1kxd3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.218.52 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=1728824401; 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=YUH0O52iG9NocMBQX2ifD6HnZr5R8mVmxmATQ3anrSs=; b=1bRIHIeTJiY15YjdeTir8WiajGUPhb65415P+RlFpNCZ4FEWTe7+byWP2VvJC33rAMAErZ mIO5SnsyXiEr6s8ErPGyLRcbAOaNVFKgOdN3P+yads30L9P5XDxZaMscdbafHnSutwo+Gj OcH/2CkgS1yxZwNBUeSHXmbCW/GuMlc= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a994cd82a3bso501508966b.2 for ; Sun, 13 Oct 2024 06:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728824515; x=1729429315; 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=YUH0O52iG9NocMBQX2ifD6HnZr5R8mVmxmATQ3anrSs=; b=ApU1kxd3EOfeClb7bw+luFK+O6AopHTFlg92cDrqZ8xw8mt+4AamCcj94Dh0x6v8Dk sJKuweCbn7mYNnWrmfMiNN2meMPSeb2yOg1WFc62bvelsgBP9ggMYUGkjJ83ZMSk76gu /q+HOkHQBokWwWQ/wSphhXJRIeLq2X8W6+Vh1C07xYnk8S+ikEl7XPBmqDe1EktDgzaD ybu0FTEtidHmaNGZ0UTqrkEkio4aoJAM1jAG+LUu9c3TyXTJw9ppEMKOp6/um4M/L6JB kmggqJ2UcLgwKK76z9jh60eINoQOT8CqYuTSa8v+/MQWXS/86X3cM4eEmnT+imTy+w6a NKcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728824515; x=1729429315; 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=YUH0O52iG9NocMBQX2ifD6HnZr5R8mVmxmATQ3anrSs=; b=vqa+1aHuBkztNcPijbUiomrx8fv4cd5lQ24NQP6H5h6mFg+zlagCeoNxGlpBWJipHy F95UhuGYAO9/bXhAj9HsKiWe3B5Os/jkueGv+fOuNwlfDNtvefzEcEPgceDYJZ6gfKcH 6JeDCHCctNYYXyNYdtDEhSlrnz6rp59wghm+dViUm4NztO7DB81trfQ6kdlsg2VIAG8r lAh7vN0L0gfabFYidC9dKMlnkaCa+nllJe4lUme4QA9iW4beCcLHCU1TauICuuJ2IWuy OTyQCrc3N5j9s1CkxMQ7vZBt+mF2fQTBOwiZXrmMQRfw3bZI0UmIMZT45JSLLrfvuyO+ uqDQ== X-Forwarded-Encrypted: i=1; AJvYcCUVidAN5RlCZCBRzILloSaeUUUaKMF0TdyRiuvzSC6owdhbNpDwGHviaL9hIuGvCwxHkHWC2KfY/g==@kvack.org X-Gm-Message-State: AOJu0Yy4gH+S7wFRABVtKpuFbWUt8TH/poOkfscVAOpOcK+xSJO9HgZk I/Bm4EhQ2JIPq4A2joO2AvigA3Ogz/IUexb7t0BFHZye5WNbRbnS X-Google-Smtp-Source: AGHT+IF9TP9UXY7+Xn/KTanZ8SmeeHtdh4zwU64TMJUgxaxAT9yUrVHKBUO3RgLezRWQskcH3dLtjw== X-Received: by 2002:a17:907:2d8b:b0:a99:399f:cf2b with SMTP id a640c23a62f3a-a99b93ae7c8mr624523566b.12.1728824514634; Sun, 13 Oct 2024 06:01:54 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0d9de967sm19209666b.139.2024.10.13.06.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 06:01:54 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: akpm@linux-foundation.org, dvyukov@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, snovitoll@gmail.com, vincenzo.frascino@arm.com, elver@google.com, corbet@lwn.net, alexs@kernel.org, siyanteng@loongson.cn, 2023002089@link.tyut.edu.cn, workflows@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user Date: Sun, 13 Oct 2024 18:02:09 +0500 Message-Id: <20241013130211.3067196-2-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241013130211.3067196-1-snovitoll@gmail.com> References: <20241013130211.3067196-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BA3F314001D X-Stat-Signature: dd7yti4kxqzmjab79zg13wc6eb95ycpr X-Rspam-User: X-HE-Tag: 1728824512-962543 X-HE-Meta: U2FsdGVkX1/nl1QwcoNR9i5iaTKgNwJFT/1sB02qmtd+C1hcwtA119+2hBLp5vHIoo+C2+ihIMDIsmTT4MDTW/9INOyGjjr3rDD+8qVkkhyto4S5FMi+EYbaLZgr6uo6RNOY9/1XDxbZvA+4VIEeTB7fCYnHL9A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TWA7bCJBGogSbWclDxO+ocRPd0mHVvGD8vnWrDzOYPHLiWDCZUAb3vL75msEfNW+rE+b38sQrGLM3g8vvTKe+TYeV1Xvxr9xNExbkkoVgt7lky/gIKXz+74WXxtRgECHv6vzXWWL43C+Zq28SPkM5V9t58JJbQ12NOZjXKW++LeJQbAVQ0PDfDB/5cA8mB349PqkQCWLRfiPGH/Psf2HMp4hhT3UfbLeBxyC02FFnplHUnkkBYJdP3zGaim1MA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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") Signed-off-by: Sabyrzhan Tasbolatov Reviewed-by: Andrey Konovalov --- 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();