Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6061273rwl; Mon, 9 Jan 2023 03:49:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXtgbmm5u8GlkcoKz8mZX3s9q+EPbDNkL6gg+mJv8VsIt7S1SNuG9mphd6lcJl13OAQKOk+H X-Received: by 2002:a17:902:e543:b0:189:a6b4:91ed with SMTP id n3-20020a170902e54300b00189a6b491edmr96235044plf.17.1673264972981; Mon, 09 Jan 2023 03:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673264972; cv=none; d=google.com; s=arc-20160816; b=nFLPNhdY/4ZVL20L5AdsJVMfdWWiHXHKtEI1ponvLhdSRYygQWo7khJUVAJV3j/ZL6 8dtDYl9mf4MpAec6qEZ0HJNPjTbPuQj7pLGREg28Lyr8Xo8CGwresji4LnX9kJLNpOa9 N00hvTk1/6aeLVwSVkfXDxz7Qs+9hrVrh9rSKKcZHL+SBDgZIS0GrV0PZb2UY84H5nnH ghIjRmrla1qoFhuHGpm7LrXL+Uu5bMGGYR3hYA2KJJZ1m05lAfidz1TvcSTpBfSbK0N2 KRu3ZRM9yvFbu6khiWGK5CDRRw9LaVpUnI2b1DFTJyvEUMniH0QO4pX3FxFZlbB99rea yGkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lmaR2eYC2v5730qz2h75zYa1uXzXfMud7j/GTNEgPCs=; b=FUmspsdDtjbXVV+JCzR5KDX2wOTDxm1zXbmAeWDOPNlX3TTubHkqfRuPzGW9YmQE5b 4jN+IPjxIXWyik8Gu2YgMy+itx+BV0v5+3yHvIsZpfwImtbgltnSDEOKYoX9artEa2n2 ei+MwyoH0cWCudp80745LmUFBlUxti3Uh30BRthUEQ2K4TX+tD8vNPVjsQJ9tRguxG4I rILG5oAXZRJJD5pkD0FAj9O5qr8+66IkaxG1trcBma+SpjM9bWlQlvpYVu+eZ+L7gLtU W1D8SJDX5VrO0yTFXkKW76gkFulSTKmS/qHD9JpW3Dsa8vI8uJQ5Ed/+MSCMh/UtrTIX dz2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RbWuARBb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b004b2b138fff9si4168502pge.47.2023.01.09.03.49.26; Mon, 09 Jan 2023 03:49:32 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=RbWuARBb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236827AbjAILX7 (ORCPT + 53 others); Mon, 9 Jan 2023 06:23:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234863AbjAILXq (ORCPT ); Mon, 9 Jan 2023 06:23:46 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C50C183B9 for ; Mon, 9 Jan 2023 03:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673263425; x=1704799425; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=9gowqygYGDzqp90nSSibk1ac34lVOOMu4128ilX28Mc=; b=RbWuARBbNX2nDWFvRnmEH8xT1Ddwdzro+Ky2udFewXlAkwGz+GkYohOL 3kFU/FZXT3+afdz+K/eQyappX78hj/fmHOti1ODjbW4QKgF4xy1Clxppc pkjG5Ecw9eaSziVL/i7DJgZoHOFtAqITqboDX/KHgObhpsBDJm7eeP8Kq ploaPq2Blms/4JWiErjBiFoC7fpom+44b/dZBAl/IzqJBlVVHEJ16d8dG /h89oN8uNmlGIgJjLMDWILQFZ5H13tvOJgcQmmZbMIgVDJfmiP93hCjj+ iIA65ipsQUvCc1YOM19+ajU9/YgGLmHBzdV18sbRg8oHFzmQBNK7kaU1V Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="350063288" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="350063288" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 03:23:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="658562782" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="658562782" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga007.fm.intel.com with ESMTP; 09 Jan 2023 03:23:42 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pEqFg-006Mal-2A; Mon, 09 Jan 2023 13:23:40 +0200 Date: Mon, 9 Jan 2023 13:23:40 +0200 From: Andy Shevchenko To: Sergey Shtylyov Cc: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: Re: [PATCH] vsprintf: fix possible NULL pointer deref in vsnprintf() Message-ID: References: <1f4d159e-5382-3c75-bd5e-42337ecd8c28@omp.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1f4d159e-5382-3c75-bd5e-42337ecd8c28@omp.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 On Fri, Jan 06, 2023 at 12:16:31AM +0300, Sergey Shtylyov wrote: > In vsnprintf() etc, C99 allows the 'buf' argument to be NULL when the > 'size' argument equals 0. Let us treat NULL passed as if the 'buf' > argument pointed to a 0-sized buffer, so that we can avoid a NULL pointer > dereference and still return the # of characters that would be written if > 'buf' pointed to a valid buffer... > > Found by Linux Verification Center (linuxtesting.org) with the SVACE static > analysis tool. ... > + /* > + * C99 allows @buf to be NULL when @size is 0. We treat such NULL as if > + * @buf pointed to 0-sized buffer, so we can both avoid a NULL pointer > + * dereference and still return # of characters that would be written > + * if @buf pointed to a valid buffer... > + */ > + if (!buf) > + size = 0; Do we have test cases for that? And what's wrong to print "(null)" ? Have you checked if your patch makes any regressions to those cases? -- With Best Regards, Andy Shevchenko