Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1112224rdg; Fri, 11 Aug 2023 10:04:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1/vyDjqR6qH+BWgQLrgddWbAiIJgdXa0+R9msPTp2CtW45omJ3z28iNM6/D5otFuWV98H X-Received: by 2002:a17:902:8bc5:b0:1bd:a22a:d406 with SMTP id r5-20020a1709028bc500b001bda22ad406mr2142342plo.21.1691773450056; Fri, 11 Aug 2023 10:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691773450; cv=none; d=google.com; s=arc-20160816; b=poBVoy9K8YnVmfNjpGKX6e47eLJxYL/edL2dAW7znBhaCHy5N4ZuuW6CcptweU18dP VqyAm7A++Q92nyAz3g+XUC98ymSkFbpXl3CEljK/bEwsMvmoxLhPv3SoA+z9VDaUZPLk jvvLWxil0++7vnC2SEMe9sCdGzVQdsd8sH+em3vXL4i93HndZGS5ztd6bPJhIBFmrTzp rWqL8YHHPzfNRye6eBJ5iNIXcjx8naxQfhNCQs5YQgGZlaQfBuxvlmbWotMpo8dgRieD 28T4S9ysG2JXhjb7G0Eg2gm1z6MRPIpEjUwz/feAWd3JYre+6u3Zo3YMNIhxFERxFfQW 0Sgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=W3QlfQPf/mhvsUrrEpuciPnw8YcCrut43G8ZIaPlOQ0=; fh=ehtjRFdpibbY0YwVQULhyaYjO7TDeFKUpFCfILKllfQ=; b=ksa79VfDPjF2QLopC07RDEBbPG/JhylAwuF9RzWLmyX1omKzizW7ciYfXXVWnG3jkf 3M1NgZ/aYeiNxvfKtYAwjKpU8Hsuf8ZsCkBf88RyKIOMX985ED0qwqNKXk7rFWt2WENw sIYw5P+ARIXwk04DymX/H3BR1zh2yaQrYvNZW4ssOiPrmfdcXItp58b853Xo5edhCzFk 2ZGGBWvqIvlR2EDMlvrtMsGeDO+B+lmSqq9WiyZHpxTPAjASwPZ4CQB1lrtS1pfvOvl2 5r+NqQap3tEQpekHrTYNxHlwcl1l50dqRfuJlQmcH38otY0Q6/ZIXHLnX31n0GNhuo+P CweA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tyhicks.com header.s=fm3 header.b=rq1RlGSc; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=qmNm5DWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a170902d49000b001b9e9b21249si3616778plg.649.2023.08.11.10.03.54; Fri, 11 Aug 2023 10:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@tyhicks.com header.s=fm3 header.b=rq1RlGSc; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=qmNm5DWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbjHKQxy (ORCPT + 99 others); Fri, 11 Aug 2023 12:53:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbjHKQxx (ORCPT ); Fri, 11 Aug 2023 12:53:53 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D5130C1; Fri, 11 Aug 2023 09:53:52 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 5EDDE32001FF; Fri, 11 Aug 2023 12:53:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 11 Aug 2023 12:53:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tyhicks.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1691772830; x=1691859230; bh=W3 QlfQPf/mhvsUrrEpuciPnw8YcCrut43G8ZIaPlOQ0=; b=rq1RlGScfenEom/BZ5 mh5DqdQFANtcENVmz1ZAe1+woYnjJlXGpi4QGvKSHV0CdWGUTvpf2StJsjr4qQDy ZrA/NUhULu2Pr4fvOMPXieFrjfhN+wtCI3JvX7lPKvgT4Fyp7/Y8ijDSgiC9cY1W sIBituV1M9VDfjLYRPUasZS/WNnCgZaDQRaV3aoepfvkowsjAtlZDScm44hXjnwR XEtkzlQCH06mPWtAa3xo0QkzKS+H6DLZbDF6FjbF1oiJU+tIIfvZF29oZhIsLjzz NGjLfr5EVh5r4oprdx9iWm6R+09s6yrIqc8vI7Ao+v1aM2PDSj+9lo949lZYFA7m UUPw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1691772830; x=1691859230; bh=W3QlfQPf/mhvs UrrEpuciPnw8YcCrut43G8ZIaPlOQ0=; b=qmNm5DWVpIG9SgcAJYhVSgVOFi0gJ ShmFThzYAQY2nerhQPStN4DEK9Klef2gV7qOhe8pZIbMZmAEDKMFPp65BWW+TwqA lmay1DrejRorvFGPP1jnFpCPkfGdjfhc8H9ZpJS3YKpUOtW7FIwJpEjoPKrVudV8 fwNizWihX07PcLVxEdFwOrzOzSfgpCXiBFdpNwhL6Hhq9A8EGgH+VH+DAauyM3gY jhqeiNzKqzzVqd0OpJ3yrDU+BbH66hZsywDIoJ++o35KJ8nVS5g+JIAK8fL+avVK tlm9IybVbnmo+y3mWvZc/VyPK8+kkDzyoZDv5Kv2gWbtd8EQESc70+4EA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrleekgddutdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfihlhgv rhcujfhitghkshcuoegtohguvgesthihhhhitghkshdrtghomheqnecuggftrfgrthhtvg hrnhepgfegkeeiffethefgteffudfhfeejhedvjefhjeekudelffdulefhfeekieeludej necuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegtohguvgesthihhhhitghkshdrtghomh X-ME-Proxy: Feedback-ID: i78e14604:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 11 Aug 2023 12:53:48 -0400 (EDT) Date: Fri, 11 Aug 2023 11:53:37 -0500 From: Tyler Hicks To: Kees Cook Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , Vijay Balakrishna , stable@vger.kernel.org, Tony Luck , "Guilherme G. Piccoli" , "Paul E. McKenney" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] printk: ringbuffer: Fix truncating buffer size min_t cast Message-ID: References: <20230811054528.never.165-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230811054528.never.165-kees@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-08-10 22:45:32, Kees Cook wrote: > If an output buffer size exceeded U16_MAX, the min_t(u16, ...) cast in > copy_data() was causing writes to truncate. This manifested as output > bytes being skipped, seen as %NUL bytes in pstore dumps when the available > record size was larger than 65536. Fix the cast to no longer truncate > the calculation. > > Cc: Petr Mladek > Cc: Sergey Senozhatsky > Cc: Steven Rostedt > Cc: John Ogness > Reported-by: Vijay Balakrishna > Closes: https://lore.kernel.org/lkml/d8bb1ec7-a4c5-43a2-9de0-9643a70b899f@linux.microsoft.com/ > Fixes: b6cf8b3f3312 ("printk: add lockless ringbuffer") > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook Nice find! Reviewed-by: Tyler Hicks (Microsoft) Tested-by: Tyler Hicks (Microsoft) Verified the fix by applying it to an instrumented v6.5-rc5 kernel that allows userspace to execute kmsg_dump(), detects NULL bytes in data copied from the ring buffer, and warns about invalid truncation due to the min_t(u16, ...) casting bug. Everything looks good! Tyler > --- > kernel/printk/printk_ringbuffer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c > index 2dc4d5a1f1ff..fde338606ce8 100644 > --- a/kernel/printk/printk_ringbuffer.c > +++ b/kernel/printk/printk_ringbuffer.c > @@ -1735,7 +1735,7 @@ static bool copy_data(struct prb_data_ring *data_ring, > if (!buf || !buf_size) > return true; > > - data_size = min_t(u16, buf_size, len); > + data_size = min_t(unsigned int, buf_size, len); > > memcpy(&buf[0], data, data_size); /* LMM(copy_data:A) */ > return true; > -- > 2.34.1 >