Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2498392rdg; Mon, 14 Aug 2023 04:46:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN04L+QqkJL19x7zFZ/JCADiUPi11d1+Pe2ngxxygokO9ZMq2Jt95kzoQhFg5sn835HXL9 X-Received: by 2002:a05:6a20:3d23:b0:138:64d4:b055 with SMTP id y35-20020a056a203d2300b0013864d4b055mr14146331pzi.55.1692013582920; Mon, 14 Aug 2023 04:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692013582; cv=none; d=google.com; s=arc-20160816; b=LXtTTaYL5uNVFHUgle/cHA5UExns+uCPUVLmiHechABOQy3AyXuNJLcqUKwy9nRyGJ CxuQpUSV+Ck7P9jjtBfDvF9kNo2nfssCQ+G/MPEQeMgCt4aiQALU8UIjQfWWCDB1K2H2 +7/3m1AufQnDpWE1An/J2FA9WwQnXahTT/oMGOshd3qiwmuXE3vdRaiAfZtyp6uQufvH P2SKYQVTOW/FW8Pi8mTbE4SGzwsz5kM+MXGbBNp2+nehIuPL+jDtO5/2Ib1gPqsDi6X4 wrEscIQm+IjLJKWXF7zGSBBIKvSAlfKLAzpkgXO/6Fxj3Ba4RnqEnWbU59FUQ6628gkq 12RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=HJb058/9Tu4PooITjuePwrKpWOFga+GsYSciXN4xaFY=; fh=vLcm65la+V9/jj7/1CwUQAfWdixRBF8WVeQRUL+zqls=; b=ANnOedUfOba0MnLVfQSEaLKgAxPnOXXY2GG4OyC5OgP6FumOqRZASn2syWuKfl2jOK nbR2fc6X92SwZhAlm0Fgeho/0bSBMHBnoPC2z9B0Wg8YloE69f+dHrxT4aARxoHOqZ0s wF6pCGVf9KU6eyvAM9O1FDmtwc4EpqeMZY3tEqopCZd+tZS1lrmYiHfpWkCJXNs0LHWk I51qnGpeCwiI6Glaemcx+4LyGoul0ww5II0HWxRgIndD9gPGX0daw+85auB7+wtwRFDc CQBPwrjYXU5pS41dxEZC3vWSwRGE07AkXgubKcl7S9wqv3ngIql2EXivdXJWtPVbwnTw X6hQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t19-20020a056a0021d300b00686e01db946si8305703pfj.64.2023.08.14.04.46.09; Mon, 14 Aug 2023 04:46:22 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233470AbjHNKnV convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Aug 2023 06:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235524AbjHNKmo (ORCPT ); Mon, 14 Aug 2023 06:42:44 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D692F1708 for ; Mon, 14 Aug 2023 03:42:40 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-10-bYN0va-pOwmudf1yAI4-aA-1; Mon, 14 Aug 2023 11:42:38 +0100 X-MC-Unique: bYN0va-pOwmudf1yAI4-aA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 14 Aug 2023 11:42:26 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 14 Aug 2023 11:42:26 +0100 From: David Laight To: 'Kees Cook' , Petr Mladek CC: 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 Thread-Topic: [PATCH] printk: ringbuffer: Fix truncating buffer size min_t cast Thread-Index: AQHZzBcPYpG1g1kNlkm6DrLi5BIXA6/pnsfQ Date: Mon, 14 Aug 2023 10:42:26 +0000 Message-ID: <42a1e2099fe141c3a57e808cbf06d8a0@AcuMS.aculab.com> References: <20230811054528.never.165-kees@kernel.org> In-Reply-To: <20230811054528.never.165-kees@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Kees Cook > Sent: 11 August 2023 06:46 > > 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. > ... > 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); I'd noticed that during one of my test compiles while looking at making min() less fussy. A better fix would be: data_size = min(buf_size + 0u, len); Or put an ack on my patch 3/5 to minmax.h and then min(buf_size, len) will be fine (because both arguments are unsigned). David > > memcpy(&buf[0], data, data_size); /* LMM(copy_data:A) */ > return true; > -- > 2.34.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)