From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B70FE224B15 for ; Sun, 9 Nov 2025 18:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762711626; cv=none; b=O0bKLNMJeEOW9JC60PW/PiBjW1hbwpuiovizgsMnVaNqPFNcp4/NS9aaAfgKhyAq0AnN1WDnm9LPsNUelZkD8yfwF2LRmsslVv2t4+zUPjQwj9Ev2NA1zxLRZUFSgT8+MHQ81Zl0uKoi9gKXQqcxvdzYQq57Z3KC7k7zT60B1cY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762711626; c=relaxed/simple; bh=Rsfmd7zbC+kSZ3iat7Z+yufKodHJKLHaalHhwgTU+L8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t5oeC3gp0QuqSi3c3tGSXchzNC1ThhajnA/OMMRXsYlm2pm9pkYp77TpLYLKpIRhXo7w37iHU2kSBEDz31TU6Nh/IpGpR4vpVfOAK6aFM8copUmgMzvaq27Ckn0XtrQFlkDAY6gLu/d4KXgaijF+TvR3xojqgpd12CA6DCH2XmY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r4l6bBR+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r4l6bBR+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F22BC4CEFB; Sun, 9 Nov 2025 18:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762711624; bh=Rsfmd7zbC+kSZ3iat7Z+yufKodHJKLHaalHhwgTU+L8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r4l6bBR+x/wYLFdBSbtrGEd6woZznOFVZnH0r9s2erJWpuz7nykmFQVCQpBbw0PHi kBR6AJir9BuoO165Hel1lDGlfK/BIcg6S5gINxdT7rhP0fBX/nyAEUVlS8lJKw0Sau IJNrXe4OD7939BXLdQ8qB9qMLdPMw3QM4EQFodO2PPj4qmoTr6tG9z1u8daz/GGBIJ wLzSxhLIt3s7zxeHLaCuXB2ghbY4o5Mo9P4rs+A+HTZa5H96TnEWQLZq61NM1NAk3A jrNv2m1xnfwMfiPoZWq3tdUYE+jpmmGcmg4dP/kQZUTert0ZpVnmANvFht9GimNVB7 EwgZihfV2WUtw== Date: Sun, 9 Nov 2025 19:06:59 +0100 From: Alejandro Colomar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Alejandro Colomar , Kees Cook , Christopher Bazley , Rasmus Villemoes , Marco Elver , Michal Hocko , Linus Torvalds , Al Viro , Alexander Potapenko , Dmitry Vyukov , Jann Horn , Andrew Morton Subject: [PATCH v3 2/4] mm: Fix benign off-by-one bugs Message-ID: <831155f02bec5ed4ef2be1d427ea18c46446c127.1762711279.git.alx@kernel.org> X-Mailer: git-send-email 2.51.0 References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: We were wasting a byte due to an off-by-one bug. s[c]nprintf() doesn't write more than $2 bytes including the null byte, so trying to pass 'size-1' there is wasting one byte. Acked-by: Marco Elver Cc: Kees Cook Cc: Christopher Bazley Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: Alexander Potapenko Cc: Jann Horn Cc: Andrew Morton Cc: Linus Torvalds Cc: Rasmus Villemoes Cc: Marco Elver Cc: Michal Hocko Cc: Al Viro Signed-off-by: Alejandro Colomar Message-ID: <515445ae064d4b8599899bf0d8b480dadd2ff843.1752182685.git.alx@kernel.org> --- mm/kfence/kfence_test.c | 4 ++-- mm/kmsan/kmsan_test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c index 00034e37bc9f..5725a367246d 100644 --- a/mm/kfence/kfence_test.c +++ b/mm/kfence/kfence_test.c @@ -110,7 +110,7 @@ static bool report_matches(const struct expect_report *r) /* Title */ cur = expect[0]; - end = &expect[0][sizeof(expect[0]) - 1]; + end = ARRAY_END(expect[0]); switch (r->type) { case KFENCE_ERROR_OOB: cur += scnprintf(cur, end - cur, "BUG: KFENCE: out-of-bounds %s", @@ -140,7 +140,7 @@ static bool report_matches(const struct expect_report *r) /* Access information */ cur = expect[1]; - end = &expect[1][sizeof(expect[1]) - 1]; + end = ARRAY_END(expect[1]); switch (r->type) { case KFENCE_ERROR_OOB: diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 902ec48b1e3e..b5ad5dfb2c00 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -105,7 +105,7 @@ static bool report_matches(const struct expect_report *r) /* Title */ cur = expected_header; - end = &expected_header[sizeof(expected_header) - 1]; + end = ARRAY_END(expected_header); cur += scnprintf(cur, end - cur, "BUG: KMSAN: %s", r->error_type); -- 2.51.0