Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2713264pxb; Tue, 19 Jan 2021 04:24:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpXipqnNhCoZ6E0MNQEkWNuaWAhOaRF2uVwC4EZgtRuHORGUmIvmXDQv60vPjsWH7FLjXT X-Received: by 2002:a17:906:3481:: with SMTP id g1mr2855215ejb.5.1611059063648; Tue, 19 Jan 2021 04:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611059063; cv=none; d=google.com; s=arc-20160816; b=bq3wbavsVwZO3g7kam3z61f8X7Wk6nEU0CgYkncHtao4PDQgMozsPgxfeIF7To8E8V D5buRoTYp++CmYCz9P6FTJNNBC/NVdGyCLkNaDtrAex+Eoy6z8rYNwtBFK+49FV7dQgc TJqDbMO0+iSL34jvfnXxbV1x7LXHQfPZrBFVh8HZsdR+4v6tk8iPnVWLuB8RoYBDPcFD f2OiMh123991xZJddWYZmbPs83kLm4Nbp+eRwoXhfFLBsr8Vbq+TEa3xJcd2ppnIDMZ8 pCjRtN8fqNy3o15f66L80S0LKHpMDyOV8ROY8/klTfMTbz8xfDBBe7ECa9TJrMjxrCAE iOaQ== 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=hWu+DiewVvlL1LmVaj1P5EWMhhS1qD2S88iFimQfQiA=; b=BwZrZomqx/0fstg6JPh8iwnCaEvW3Qgi9CaJcjlre+WZL0Zm3skzCtepKveDxmi8ts FK6LxeQ2zOs6dmV1/tg0mbWqGdNz5z7oebwNssSGZ1GCQ1cIW13phW9svyUxkhQ1/9JB +JEJXET4Gq9sWFtpKrZrtAyO7ANI4fPYuYFpwhs2DfhFjTnLM5Y/pzcdl/TsO+yQgnFK KovZJhtY5QwdwDPBPujGGPMSQD9rxwnx1rkmRvB4GCM59sDPR2WC9p6G5Ci5CVloJf62 dk+0CSZzXLPVs5Na2UpbDjZoQjhb8Ua6Fphhk6preo2zUdIFHZPlVi3YNwWsrVs6YCEJ mutA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=u+9iQaqA; 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 pw18si3898031ejb.416.2021.01.19.04.23.59; Tue, 19 Jan 2021 04:24:23 -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=u+9iQaqA; 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 S2389884AbhASLcf (ORCPT + 99 others); Tue, 19 Jan 2021 06:32:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:42146 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388820AbhASLUv (ORCPT ); Tue, 19 Jan 2021 06:20:51 -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=1611055205; 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=hWu+DiewVvlL1LmVaj1P5EWMhhS1qD2S88iFimQfQiA=; b=u+9iQaqACTIILNUbsmGHGAbTTV7d8oElPwb1A8brtM67ZWjRmamG/cIfHT9MaljRbrWThU iNB2/TB6PE8l/K1fWGuMsJf5yOCsFk7lB4TQBTw5cFeNXhTT7vPpprKDn105hVdosXdNrA TpVj71TnbBKioWefssKs+RR6CQmqPRo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D501DADE3; Tue, 19 Jan 2021 11:20:04 +0000 (UTC) Date: Tue, 19 Jan 2021 12:20:04 +0100 From: Petr Mladek To: Sergey Senozhatsky Cc: John Ogness , 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2021-01-19 09:44:56, Sergey Senozhatsky wrote: > On (21/01/15 13:07), Petr Mladek wrote: > > On Fri 2021-01-15 13:04:37, Petr Mladek wrote: > > > 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 > > John, how did you spot these problems? > > FWIW, Acked-by: Sergey Senozhatsky The patch has been committed into printk/linux.git, branch printk-rework. Best Regards, Petr