Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1212526pxb; Thu, 16 Sep 2021 02:18:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFt6r0H0XR16RKWswd44UuLGwhlOTEuggwG7MWHywMU6fqgGGFaIGC35B3Wzf6VW5v5+WX X-Received: by 2002:a05:6638:2182:: with SMTP id s2mr3582624jaj.26.1631783880655; Thu, 16 Sep 2021 02:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631783880; cv=none; d=google.com; s=arc-20160816; b=mwEB73hYBtExqOLtVQzG29s2bBviSh/Nhe46iR6OH4rDr7pCs0pzEVPhJkvAXckqmA E54dy+IZDb0ZNaOnsorbyp5/+w4YQvoyrG7i/UvsER9vNCQUMcVooRCoOdaGuS5gGPh3 iU5CJGFPk/QN1U9jnLyFVde0qMun/1t+lGMtn6v5r141QvILc6VeSAsA62p8+tymMekQ t7T/1RZcOgvK3LxdFzXwk/vf8W3NQLtl2ntmuNrv0QfZeux+ZDqIKMRyHb8NQx9hQq/R ihohkReXbNuLvS/TCG8G4IlY1XYEHEdogVanS38nWriATvVHg5BEHLCA/noSq56rtzdD vR5A== 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; bh=TDUJzM12ZODqqKrW4urCZqeGKWVcsC7fGaCc7DJiqEE=; b=B+bM025W1P9WJWqqmuTWF3TQ/kiY/O9JMZR33RX766k4+em1wNKmCCZYhlPVP3E2Ge 0A4qoxiA/Jy/RI7Cy/wKMML4uuj8p6YU+dO6AWZcPpWC6GlkXdXSnfyzyRjQtrZExuH+ Jpj0Fa9xO+bjIDMh8xQQYYoapbwlc+qSXdZySYKXmWuBb9AyVkYi4Nr9VXx1uHQeDR9g Ousi0+xSH9LoznmpcGEO2V9jxp1dLC92Gv++nb8gKV0Z6WE2vhG5bbXjSYOkNKf7svGL gFwLQiJYxCPRf+7gEdl2pQe5MXeGEtKjPua9MU+/N+mGBv6IWuQvSJM8xY7gxSb6sW6Y k7yA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si1981254ila.156.2021.09.16.02.17.49; Thu, 16 Sep 2021 02:18:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235783AbhIPJR1 (ORCPT + 99 others); Thu, 16 Sep 2021 05:17:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:41760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236388AbhIPJQE (ORCPT ); Thu, 16 Sep 2021 05:16:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD47560F93; Thu, 16 Sep 2021 09:14:42 +0000 (UTC) Date: Thu, 16 Sep 2021 11:14:40 +0200 From: Christian Brauner To: Vivek Goyal Cc: viro@zeniv.linux.org.uk, Linux fsdevel mailing list , linux kernel mailing list , Jan Kara , xu.xin16@zte.com.cn, Christoph Hellwig , zhang.yunkai@zte.com.cn Subject: Re: [PATCH] init/do_mounts.c: Harden split_fs_names() against buffer overflow Message-ID: <20210916091440.zk2qvdmldo6wkryi@wittgenstein> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 15, 2021 at 11:22:04AM -0400, Vivek Goyal wrote: > split_fs_names() currently takes comma separated list of filesystems > and converts it into individual filesystem strings. Pleaces these > strings in the input buffer passed by caller and returns number of > strings. > > If caller manages to pass input string bigger than buffer, then we > can write beyond the buffer. Or if string just fits buffer, we will > still write beyond the buffer as we append a '\0' byte at the end. > > Will be nice to pass size of input buffer to split_fs_names() and > put enough checks in place so such buffer overrun possibilities > do not occur. > > Hence this patch adds "size" parameter to split_fs_names() and makes > sure we do not access memory beyond size. If input string "names" > is larger than passed in buffer, input string will be truncated to > fit in buffer. > > Reported-by: xu xin > Signed-off-by: Vivek Goyal > --- Strange but probably reasonable, Acked-by: Christian Brauner