From patchwork Mon Sep 30 10:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13815820 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 3BB26CF6497 for ; Mon, 30 Sep 2024 10:23:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78DDE6B00D9; Mon, 30 Sep 2024 06:23:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73AC780017; Mon, 30 Sep 2024 06:23:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6042B6B00E1; Mon, 30 Sep 2024 06:23:22 -0400 (EDT) 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 44E5A80017 for ; Mon, 30 Sep 2024 06:23:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F18241409AA for ; Mon, 30 Sep 2024 10:23:21 +0000 (UTC) X-FDA: 82621017402.07.B6C37DC Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf05.hostedemail.com (Postfix) with ESMTP id 3325010000A for ; Mon, 30 Sep 2024 10:23:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Q1eN70/n"; spf=pass (imf05.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.167.52 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=1727691632; 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:references:dkim-signature; bh=GmEITXlR0ceUxPN6rul6hZDhcOAMvvwj8hZoqNcz/nE=; b=EyVbUBDWWFRqo1HopARwUnxsS3JrMow+XzckIShIXNZ3pDnebu90KzYDupGlhOC3RmvQrS aEmIYPfTQbwbKc5y5PXehU+VqAvKGt8myhI5oM2sdIiIoxkjMKNWQVypK+Ps1w/qYpqwjY JmA/T0Ywi9+ROv902CW6QCaJcIay0vM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Q1eN70/n"; spf=pass (imf05.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727691632; a=rsa-sha256; cv=none; b=x14MeqSWiW/NqtxtBr1XIpJsucITkyxEMb7pfz08CeN5oNiIJ76s7cR3eP96naR2uGrzix lxnxMRtAN4UnJAXv+9Cubu93zWZQmjLQ6FCXFMz6a39+dr505WLCLzMZktVCi465kWG+Ie PI5NOF62C6cNGMzkNthLg3e/QOyN6iM= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539973829e7so511076e87.0 for ; Mon, 30 Sep 2024 03:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727691797; x=1728296597; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GmEITXlR0ceUxPN6rul6hZDhcOAMvvwj8hZoqNcz/nE=; b=Q1eN70/nubrlyPkgzZ+ydVJx5T272uTFUm7wMntPi/kxgJa4KONgTprDTQPfKJIj7T Acp+2bC3FNIFGMAGO/zAatCAZNt8S9eg5O0Fv8nAIkp3ugUP9yIXaXBI7ir8PTNDOYI0 D/NUhSR4FdhIhDn1Qy1Q9suHWzcEdKRvFzD04RFW2Dqxt1ST2OAwFC8n3JKUY7D+Icsh +ycelHUCCF1H4qw1Ue49VrBN7Tc3DXZ12OB504rB98OB0omDvnkDzdiQOyRs+GvMqUPK iCSY7PLVYkK63vWj/TgJyWsiNm0thFk42Tr50ZMrjiBHwSlKaySyKevK/6z52L9+Qd9L 9RVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727691797; x=1728296597; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GmEITXlR0ceUxPN6rul6hZDhcOAMvvwj8hZoqNcz/nE=; b=FvsjpS5twmhB9tdOMmKbZFXBTxHVLJ0Bbx2xGRWBTf7hddG52qFJJNNNrpjyelWH1S uhrCCibKPn9tpJBHNMTQXyjjUS+jOsmN45jnFuL9aDL2h1g0DBJsOY/3tP+RhaL0DFgs 7yu/TQF4S6RRixERQ1gPl80xtBJlFRCDVkA/wS0vOi8PmTOaroWGd1/iaztWkw9AycU2 33Fwwerwm2IuogT5btCRwnpkzbiyJuMKhYDLsQX//YLLcI8+fHC5P/hpejPzWLWJYElZ pcu5jxufZ5LnHfBSwkVDa+u2etQMazLJaQMNu+DFUXJjvwEjajCWhTwcZD2xEpxLICO7 3X1Q== X-Forwarded-Encrypted: i=1; AJvYcCX+tw8ff3A5oCSIA+Z9MY79S6PrFZ2JgZsFwDbbdt/nOBRlPnIbUSEdD3d0FQAN2jAY8tSp6FdpNg==@kvack.org X-Gm-Message-State: AOJu0YyKzrsYlN0KlEez9zY2/bZSmvIGQqbW9byBfDzRchQ/tLG06Ubz oN/+t9S5yq291+3EH53yzlCGfL92NDrOztYT+R5By7Z1hZpbG9Bs X-Google-Smtp-Source: AGHT+IHnQtAkIBhaWFdwFHnkp+CnZByohDf1mJVlXB2WmbSuBqwW0DU+WU4shf7k5U6O7yo+yKUZcA== X-Received: by 2002:ac2:51ce:0:b0:539:89f7:3187 with SMTP id 2adb3069b0e04-53989f7343fmr4800401e87.47.1727691796866; Mon, 30 Sep 2024 03:23:16 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-539903944e5sm569425e87.162.2024.09.30.03.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 03:23:16 -0700 (PDT) From: Sabyrzhan Tasbolatov To: akpm@linux-foundation.org, dvyukov@google.com Cc: andreyknvl@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, snovitoll@gmail.com Subject: [PATCH] mm, kasan: proper instrument _kernel_nofault Date: Mon, 30 Sep 2024 15:24:05 +0500 Message-Id: <20240930102405.2227124-1-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3325010000A X-Stat-Signature: nt7kk7p1erm4dtpf5t69ibuezsftk3zx X-Rspam-User: X-HE-Tag: 1727691798-365710 X-HE-Meta: U2FsdGVkX1/91ZLC/Lvps6byoDe/2poySLH71MOLddkt5s9UA/GE1T/bXOM9CqTfuTw1x/ISHYtD1oq6zK8PhzbaWJJOVrm6OYZTuquyf6okEd3eT8oMzoPXUNh1CNAbMHuzuOunnZX9TdT/2OKmuoGxovL/h0+x3eXkzh+QM1desCx+54UHz67RL7oCZvPO1yoLe2gvGKJCu7YfSUBjYKaqauDTRoWkFbFB+nO5a5h2p4lIZYnZn4063ZGU22qgqJijUygV6P6vWn9vbueeVHOCJvZw83yhHD7znfXbaQQDN8oV4wZ5IcOZdMpn/WJVWlAegR0h6bTNJn7NE9P/2K9UJRvKVmsRgqz7oIsz0hALWcFYX8wPMCvPPiwU6uuja9Mgk3Q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X-Bogosity: Ham, tests=bogofilter, spamicity=0.018184, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In commit 88ad9dc30bbf("mm, kasan: instrument copy_from/to_kernel_nofault"), both src and dst were checked which might lead to the false-positive reports. Regular instrument_read() for copy_from and instrument_write() for copy_to triggers KASAN reports in mm/kasan_test_c.c copy_from_to_kernel_nofault_oob() kunit test. Tested on x86_64, arm64 with CONFIG_KASAN_SW_TAGS using the latest linux-next tree, where this commit has been merged today. Reported-by: Dmitry Vyukov Closes: https://bugzilla.kernel.org/show_bug.cgi?id=210505 Signed-off-by: Sabyrzhan Tasbolatov --- mm/maccess.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 2c4251df46c..f752f0c0fa3 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -32,7 +32,7 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size) return -ERANGE; pagefault_disable(); - instrument_memcpy_before(dst, src, size); + instrument_read(src, size); if (!(align & 7)) copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); if (!(align & 3)) @@ -40,7 +40,6 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size) if (!(align & 1)) copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); copy_from_kernel_nofault_loop(dst, src, size, u8, Efault); - instrument_memcpy_after(dst, src, size, 0); pagefault_enable(); return 0; Efault: @@ -65,7 +64,7 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size) align = (unsigned long)dst | (unsigned long)src; pagefault_disable(); - instrument_memcpy_before(dst, src, size); + instrument_write(dst, size); if (!(align & 7)) copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); if (!(align & 3)) @@ -73,7 +72,6 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size) if (!(align & 1)) copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); copy_to_kernel_nofault_loop(dst, src, size, u8, Efault); - instrument_memcpy_after(dst, src, size, 0); pagefault_enable(); return 0; Efault: