From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D95AAC2B9F4 for ; Thu, 17 Jun 2021 14:17:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B63CA61351 for ; Thu, 17 Jun 2021 14:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbhFQOTe (ORCPT ); Thu, 17 Jun 2021 10:19:34 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34288 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbhFQOTa (ORCPT ); Thu, 17 Jun 2021 10:19:30 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B52601FD7D; Thu, 17 Jun 2021 14:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1623939441; 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=Vk+cyjGJ36YWDJsgfR+xPOajoQrdSBKg4DxQNTPCfEg=; b=N2Z0gOflTAsA4kIhg0oygEqDHAhKnphs62XVn/Utgy0N4qsYUjrRwHDHeKnXpO5J8IIyG7 +tGkkMXA+LkycQs7tgOA0KXU8T+xIz5s2/Rv97qyIXZyWmTG5oG4kVnBC+5LvxyuqO3bgB q+J04bIs14tFsMrMPr9t6eDG+X3WQDs= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 85DBEA3BB8; Thu, 17 Jun 2021 14:17:21 +0000 (UTC) Date: Thu, 17 Jun 2021 16:17:21 +0200 From: Petr Mladek To: Jia He Cc: Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Linus Torvalds , "Peter Zijlstra (Intel)" , Eric Biggers , "Ahmed S. Darwish" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Matthew Wilcox Subject: Re: [PATCH RFCv4 3/4] lib/test_printf.c: split write-beyond-buffer check in two Message-ID: References: <20210615154952.2744-1-justin.he@arm.com> <20210615154952.2744-4-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210615154952.2744-4-justin.he@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Tue 2021-06-15 23:49:51, Jia He wrote: > From: Rasmus Villemoes > > Before each invocation of vsnprintf(), do_test() memsets the entire > allocated buffer to a sentinel value. That buffer includes leading and > trailing padding which is never included in the buffer area handed to > vsnprintf (spaces merely for clarity): > > pad test_buffer pad > **** **************** **** > > Then vsnprintf() is invoked with a bufsize argument <= > BUF_SIZE. Suppose bufsize=10, then we'd have e.g. > > |pad | test_buffer |pad | > **** pizza0 **** ****** **** > A B C D E > > where vsnprintf() was given the area from B to D. > > It is obviously a bug for vsnprintf to touch anything between A and B > or between D and E. The former is checked for as one would expect. But > for the latter, we are actually a little stricter in that we check the > area between C and E. > > Split that check in two, providing a clearer error message in case it > was a genuine buffer overrun and not merely a write within the > provided buffer, but after the end of the generated string. > > So far, no part of the vsnprintf() implementation has had any use for > using the whole buffer as scratch space, but it's not unreasonable to > allow that, as long as the result is properly nul-terminated and the > return value is the right one. However, it is somewhat unusual, and > most % won't need this, so keep the [C,D] check, but make > it easy for a later patch to make that part opt-out for certain tests. Excellent commit message. > Signed-off-by: Rasmus Villemoes > Tested-by: Jia He > Signed-off-by: Jia He Reviewed-by: Petr Mladek Best Regards, Petr