Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp315877pxb; Fri, 15 Jan 2021 04:09:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/r9U72rNd+aEIpH1EPw+crLFKhSidpNDmKwatrfZHHIUVuAaVF0c/clNh8i+7+nTX9ThQ X-Received: by 2002:a05:6402:129a:: with SMTP id w26mr9676776edv.355.1610712543434; Fri, 15 Jan 2021 04:09:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610712543; cv=none; d=google.com; s=arc-20160816; b=wU2V8DYooBlU1l5DCP1ro10uAznNfaQymtCWaEbDJb1hKcGRfz4amGtRlOhZuqSjPJ H/2GQr8tiotK1b6WMleZ80qRa0KJhyfnfdZIJiagODeJ0OoSA3PV6S9cT1+xIYxwC4tZ YlMd7h1ou0J48JhKNOJZEqbIVpyl9Su8/JaANKCTTBekm/oeNMid/BpYT/WAu0aSagoC GUhzBw43r3trSZesjsabVki6VGk639BCNfi2ff7pkDE4X1Yt2J5om3rEeE5u9spephOp 4eWbLCw6Uma9FqjpHbHKHp0WAWxVF0uDPTYpiH42Fk9vcu/R5cnSyi8grY7mJbd/X/29 kGkQ== 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:dkim-signature; bh=4/61Uo+zlVSdS9m3wBubDsgiAraVweiD6lOY4/ZHTuQ=; b=it1h2iMaFeLBO+VwBuNuu6vq7xk1wFpYdLzKk2x/LSxHvxk6Vx66H0XzNETuDvUNzg V6IA/l6sza4360ZqRDwRjNfWFbNriVO7slZCb0cx8q9gT5p5+DGIy5fLTq3o9J/kTKpl UNrMdFErHJ9rsM6gAQVjsQ0uAmlQtYFSA/RmpNOKNwEHY7HSm4c5OX3SLjekdeZM7Rv1 ACzCJXOfACvMvf0sJSvIVgpBNStliJ0+L1R8MZtpcZ55ilMyywZX/dAK3cHppDuPrxs8 zJjqXKP0ox53RTOGoKVqH3+B4UHxiFGHIENhpeIwcg3iBSoUmGEbAjKrLMv0rOOKQgBA J0Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=VUXxejLJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a89si4134519ede.326.2021.01.15.04.08.39; Fri, 15 Jan 2021 04:09:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=VUXxejLJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727550AbhAOMFY (ORCPT + 99 others); Fri, 15 Jan 2021 07:05:24 -0500 Received: from mx2.suse.de ([195.135.220.15]:57274 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbhAOMFX (ORCPT ); Fri, 15 Jan 2021 07:05:23 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610712277; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4/61Uo+zlVSdS9m3wBubDsgiAraVweiD6lOY4/ZHTuQ=; b=VUXxejLJskK+1kr9KssNyMhEnJE/9aY5YoowNaVo6ieN3RYsotlT0vx/RJ6bgI4o7dXbSp BcP+6lku6BvhF8cZbS2dWznCfEi//oQcVmQWps5JTkCbCzKGnUnu8qefK9fNV8rNyBpTL3 M4606OOBLlGjgSYYYAgL4sG/D2CQst4= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8D18CAC63; Fri, 15 Jan 2021 12:04:37 +0000 (UTC) Date: Fri, 15 Jan 2021 13:04:36 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , linux-kernel@vger.kernel.org Subject: Re: [PATCH] printk: fix buffer overflow potential for print_text() Message-ID: References: <20210114170412.4819-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210114170412.4819-1-john.ogness@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2021-01-14 18:10:12, John Ogness wrote: > Before commit b6cf8b3f3312 ("printk: add lockless ringbuffer"), > msg_print_text() would only write up to size-1 bytes into the > provided buffer. Some callers expect this behavior and append > a terminator to returned string. In particular: > > arch/powerpc/xmon/xmon.c:dump_log_buf() > arch/um/kernel/kmsg_dump.c:kmsg_dumper_stdout() > > msg_print_text() has been replaced by record_print_text(), which > currently fills the full size of the buffer. This causes a > buffer overflow for the above callers. > > Change record_print_text() so that it will only use size-1 bytes > for text data. Also, for paranoia sakes, add a terminator after > the text data. > > And finally, document this behavior so that it is clear that only > size-1 bytes are used and a terminator is added. > > Fixes: b6cf8b3f3312 ("printk: add lockless ringbuffer") > Signed-off-by: John Ogness Reviewed-by: Petr Mladek Best Regards, Petr