Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp511400pxj; Thu, 17 Jun 2021 07:45:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9FJaQkKVam+XPCfwttcoxQPyg8d67UkgVeBgfSTTUPylAnFAQRcADsAuyYXCndH4U33eN X-Received: by 2002:aa7:c619:: with SMTP id h25mr6987677edq.388.1623941127255; Thu, 17 Jun 2021 07:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623941127; cv=none; d=google.com; s=arc-20160816; b=ZyqQpSGlWdG3Sw2sMcrOmFv6Gwljan5MLpCaOf6tt7pAEouaCFyRfuOQtjSFFlftC2 7+lNn6VByaN+SgSjq0XhxGpyDQb60ujN7VpkxTEOci1fPQlaKyMOsQoLfoaOHO0qSylB R0E1mlZQmGv3AIAsQkSnnC3FZU1XCI82w31iPH0Kj08mZDjrdIIhwZDqMbIu4TA+DIxN zlG+yTsAXclAVp1jJ9hNND9sK7mmadLHDKadGt14cuirsBGwkN+5V3nGTg6pkRLnmqG4 fUO8t3wbIEIIrOv7/rqbLkbRRBnORnmUOKmSlVpqb5wIo73aCvtaiepxwU1eE3JyZcUW mAHg== 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=Vk+cyjGJ36YWDJsgfR+xPOajoQrdSBKg4DxQNTPCfEg=; b=ahVJZiY0VoIJqVS1iLxEBQtmh2y16OatyzB8ji4QHQSR0eSha9/hU10kWVz2NWGXv3 fYgIPxr/Z7atJaX+zi8n6kLtMA3qkSLjnP1LgQGrTuKD3IBfzkDYVph0US8boNAkTuqO ByPqh1ZGDwnAoA6FjqJP4qwYQoiNkenPZwkyopCs8C0iEEyRDKRFtbM5pX1cq1XEypmB OBJMCAu0nhcNgAhlAa2gdxZeLK84SZa5hz+gZR/HgXltyx5cvtWOgdLvaIKMtijxjZau 4u9V16wAMeXGc70zGFCKatGAGSWhxdsvp2y1+ButtKP+E9yZ0vsHOXESeuFrNz9vXuuu asUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=N2Z0gOfl; 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 my45si5478618ejc.636.2021.06.17.07.45.03; Thu, 17 Jun 2021 07:45:27 -0700 (PDT) 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=N2Z0gOfl; 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 S231826AbhFQOTe (ORCPT + 99 others); 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-kernel@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