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=-4.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 A7204C433DF for ; Thu, 13 Aug 2020 17:32:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 887FC2078D for ; Thu, 13 Aug 2020 17:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbgHMRcF (ORCPT ); Thu, 13 Aug 2020 13:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgHMRcF (ORCPT ); Thu, 13 Aug 2020 13:32:05 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D164C061757; Thu, 13 Aug 2020 10:32:05 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k6H51-00F8jY-9s; Thu, 13 Aug 2020 17:31:55 +0000 Date: Thu, 13 Aug 2020 18:31:55 +0100 From: Al Viro To: Josef Bacik Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@fb.com, willy@infradead.org Subject: Re: [PATCH][v2] proc: use vmalloc for our kernel buffer Message-ID: <20200813173155.GZ1236603@ZenIV.linux.org.uk> References: <20200813145305.805730-1-josef@toxicpanda.com> <20200813153356.857625-1-josef@toxicpanda.com> <20200813153722.GA13844@lst.de> <974e469e-e73d-6c3e-9167-fad003f1dfb9@toxicpanda.com> <20200813154117.GA14149@lst.de> <20200813162002.GX1236603@ZenIV.linux.org.uk> <9e4d3860-5829-df6f-aad4-44d07c62535b@toxicpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e4d3860-5829-df6f-aad4-44d07c62535b@toxicpanda.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13, 2020 at 01:19:18PM -0400, Josef Bacik wrote: > > in sunrpc proc_dodebug() turns into > > left -= snprintf(buffer, left, "0x%04x\n", ^^^^ left + 1, that is. > > *(unsigned int *) table->data); > > and that's not the only example. > > > > We wouldn't even need the extra +1 part, since we're only copying in how > much the user wants anyway, we could just go ahead and convert this to > > left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data); > > and be fine, right? Or am I misunderstanding what you're looking for? Thanks, snprintf() always produces a NUL-terminated string. And if you are passing 7 as len, you want 0xf0ad\n to be copied to user. For that you need 8 passed to snprintf, and 8-byte buffer given to it.