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=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham 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 366AEC37120 for ; Mon, 21 Jan 2019 21:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F35592089F for ; Mon, 21 Jan 2019 21:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbfAUVZT (ORCPT ); Mon, 21 Jan 2019 16:25:19 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:47950 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfAUVZT (ORCPT ); Mon, 21 Jan 2019 16:25:19 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1glh4G-0000c6-WC; Mon, 21 Jan 2019 21:25:17 +0000 Date: Mon, 21 Jan 2019 21:25:16 +0000 From: Al Viro To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, Chandan Rajendra , joe@perches.com, abdhalee@linux.vnet.ibm.com Subject: Re: [PATCH RESEND] get_fs_type: Validate fs type string argument Message-ID: <20190121212516.GD2217@ZenIV.linux.org.uk> References: <20181120053642.24513-1-chandan@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Mon, Jan 21, 2019 at 01:20:57PM +0100, Miklos Szeredi wrote: > On Tue, Nov 20, 2018 at 6:36 AM Chandan Rajendra > wrote: > > > > On ppc64le, When a string with PAGE_SIZE - 1 (i.e. 64k-1) length is > > passed as a "filesystem type" argument to the mount(2) syscall, > > copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64le) > > worth of space for holding the string in kernel's address space. > > > > Later, in set_precision() (invoked by get_fs_type() -> > > __request_module() -> vsnprintf()), we end up assigning > > strlen(fs-type-string) i.e. 65535 as the > > value to 'struct printf_spec'->precision member. This field has a width > > of 16 bits and it is a signed data type. Hence an invalid value ends > > up getting assigned. This causes the "WARN_ONCE(spec->precision != prec, > > "precision %d too large", prec)" statement inside set_precision() to be > > executed. > > > > This commit fixes the bug by validating the length of the "filesystem > > type" argument passed to get_fs_type() function. > > > > Signed-off-by: Chandan Rajendra > > Reported-by: Abdul Haleem > > Suggested-by: Joe Perches > > Acked-by: Miklos Szeredi > > Al, please pick this up, it looks like a good sanity check and lack of > it is causing headaches for IBM QA. Umm... I'm not against that patch, but I wonder if that should be caught earlier... If nothing else, the same string is seen by LSM shite before get_fs_type() gets a chance to reject it, and I wouldn't bet a dime on robustness of that code. Wouldn't it be saner to have char *copy_mount_string(const void __user *data) { return data ? strndup_user(data, PAGE_SIZE) : NULL; } use a more explicit size limit? PATH_MAX, for example?