Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1598505lqp; Mon, 15 Apr 2024 10:57:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUB/MDo693m/Khd32ACrmhacAlD0hjL9dgfXvqdHpE2qx/63DmSGGFWYL5SENt+n0yy45a59NWP0h1UfRwMhf5bkeUlNbBdz+tYPIQ02g== X-Google-Smtp-Source: AGHT+IEl3+oaXjDq/75nQhAtCmcWFvJiydU3/0SWFTjN0qD2ptkzVw7oDZGta6EJevaaYKtcgNBY X-Received: by 2002:a05:6a21:3d84:b0:1a7:11bf:7b74 with SMTP id bj4-20020a056a213d8400b001a711bf7b74mr8627359pzc.62.1713203878959; Mon, 15 Apr 2024 10:57:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713203878; cv=pass; d=google.com; s=arc-20160816; b=oH0WUmQWJxU3T7QinsIOqFjiD8RY4xkJGQ1UUg4dKUuMScVcR8tDJ5emIK62ZGnwJP OtFUa1WaOxVOELRFMdFh6xM2UxxUux84pQWtfOvCGZULHtE4v8qBRVWgT7EdsdLXwgiG iUNSxqWBKpjqvUPkSb98fNm5h/td1umjpzM9K/CUuB+K+LsX6EaVG2ZrZUoApUCy0nu0 vCggnlhaMlCcOrQWS/D+1DdoAn8iTx9Fs3LPQePQa1CcQNlP+XuWCILZy3m0r46C3/+D hdAkSelHSWalc3zy+tRaJdRPrc8yZYMWYIp1ZfuUoR+3S7J+6L7XAB6qW4uwntxHEV5w XhvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date :dkim-signature; bh=7WoF/OVhja5rh0oZfHmbZHpLS9885IhKeZTon+/iGxA=; fh=PEX+stSOUdtQHUY+GQjT20WPCI6VC+/gg8kLaxNfvok=; b=AT8J4i06Sl8tJQaBnDhBVzTx21MMR5oaG/m/vVvs2+0vE/c+kMlnyy9efTnMkcORdM Sxzvo1lqqomGX8kjbVMIDdUyUbiDCaAopQqgaice1vUfbJmPcSsFhlevtNigH+z6IALl NL5H8fTly6Xq7Yg5lfpkRby761Aksc2CXTzXYBYbAljI/wstQE/QTJ/BiUhJFgbzM8tQ +UMXWNsCAXtxNr6lkIESBkyiTHYkxaVc3kTZh+167fhyJY9cgXEXH//6wHPl6UeuOj1A phmhhSsN5yeRODV//Lm7VlITT7/DV/V1WdCdlfPzkHMtHtsFsaDEm/65DmdRqwy3c0cw m1fA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@treblig.org header.s=bytemarkmx header.b=qraoAuVl; arc=pass (i=1 spf=pass spfdomain=treblig.org dkim=pass dkdomain=treblig.org dmarc=pass fromdomain=treblig.org); spf=pass (google.com: domain of linux-kernel+bounces-145683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=treblig.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v6-20020a632f06000000b005dc98dad590si8268810pgv.68.2024.04.15.10.57.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 10:57:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@treblig.org header.s=bytemarkmx header.b=qraoAuVl; arc=pass (i=1 spf=pass spfdomain=treblig.org dkim=pass dkdomain=treblig.org dmarc=pass fromdomain=treblig.org); spf=pass (google.com: domain of linux-kernel+bounces-145683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=treblig.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D928D283492 for ; Mon, 15 Apr 2024 17:57:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF41E13AA32; Mon, 15 Apr 2024 17:57:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b="qraoAuVl" Received: from mx.treblig.org (mx.treblig.org [46.235.229.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B96651369B8; Mon, 15 Apr 2024 17:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.229.95 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713203837; cv=none; b=DMM2AqC2MipIwKecgqYqZqRoiCgxG9jiVsXzKaYcySC6CrozDmnsM6Z0BhURYPEW3W9WwRBz92+Z9zGEiw6chOQW3XCuMKkcKx4HE6Vm8AcvdX59fZuJ97evFiY/HEwRMgRfAIXNxwVIpnjxQW/eq7hvjODv2yecYrJoXobTAGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713203837; c=relaxed/simple; bh=HZXXTICwCNfNnAAPksAihITX/uhY4HG81OJG+2aD0Lg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z2zN7MvKSGEjOaU3ydJOGNCAZHa5Nh4jxc2gJ5LWGGzqa8ZkCD1hsNY7OtmEh1z9NfXzgRl3WMjPQgMrweb+gMo8lZcVeoSyHtwYwP5notr/msd9nqM4lRoIdvZ/Hxu7wHOZxc/6z2uz76MpDnQsoGQ1cWdd/K7VCJcdRDxGRII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org; spf=pass smtp.mailfrom=treblig.org; dkim=pass (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b=qraoAuVl; arc=none smtp.client-ip=46.235.229.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=treblig.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=treblig.org ; s=bytemarkmx; h=Content-Type:MIME-Version:Message-ID:Subject:From:Date:From :Subject; bh=7WoF/OVhja5rh0oZfHmbZHpLS9885IhKeZTon+/iGxA=; b=qraoAuVl2vW4OX78 0mqZnQJQzqSfaofrXipcO+bzUmf69MX21EjsLpb51ayPP4EkFCxSqG5+7ZSlKXrtuUN7GTMgPVpgK hLL6jmykX+jjjZZRq/8++IEyjyCZS2O2oDo+1/tP4TuuE2m/YuDmBumng0J9Q2Ed0/rKUsM9gqlNi FauM6xkVIFCUYF/BEn9hNqQxGwd1g9Al9TFKti28M45fYuVUUuOtoEw6mkBvpMeWzEDiwIBBQdML/ 05rpf7EMZqogpYlYkNNOHvbqnjggIIZi7c3Pi9cmnHMqFXpolHVqMn8H8LvBwNWcFcc/88CO6ySHB eJ+bzeEJsoYoSc5YiQ==; Received: from dg by mx.treblig.org with local (Exim 4.96) (envelope-from ) id 1rwQJO-001G0D-1x; Mon, 15 Apr 2024 17:40:10 +0000 Date: Mon, 15 Apr 2024 17:40:10 +0000 From: "Dr. David Alan Gilbert" To: Alexey Dobriyan Cc: Luis Chamberlain , akpm@linux-foundation.org, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz Subject: Re: [PATCH] module: ban '.', '..' as module names, ban '/' in module names Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Chocolate: 70 percent or better cocoa solids preferably X-Operating-System: Linux/6.1.0-17-amd64 (x86_64) X-Uptime: 17:39:50 up 103 days, 20:29, 1 user, load average: 0.00, 0.00, 0.00 User-Agent: Mutt/2.2.12 (2023-09-09) * Alexey Dobriyan (adobriyan@gmail.com) wrote: > On Sun, Apr 14, 2024 at 01:58:55PM -0700, Luis Chamberlain wrote: > > On Sun, Apr 14, 2024 at 10:05:05PM +0300, Alexey Dobriyan wrote: > > > --- a/include/linux/fs.h > > > +++ b/include/linux/fs.h > > > @@ -3616,4 +3616,12 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len, > > > extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, > > > int advice); > > > > > > +/* > > > + * Use this if data from userspace end up as directory/filename on > > > + * some virtual filesystem. > > > + */ > > > +static inline bool string_is_vfs_ready(const char *s) > > > +{ > > > + return strcmp(s, ".") != 0 && strcmp(s, "..") != 0 && !strchr(s, '/'); > > > +} > > > #endif /* _LINUX_FS_H */ > > > --- a/kernel/module/main.c > > > +++ b/kernel/module/main.c > > > @@ -2893,6 +2893,11 @@ static int load_module(struct load_info *info, const char __user *uargs, > > > > > > audit_log_kern_module(mod->name); > > > > > > + if (!string_is_vfs_ready(mod->name)) { > > > + err = -EINVAL; > > > + goto free_module; > > > + } > > > + > > > > Sensible change however to put string_is_vfs_ready() in include/linux/fs.h > > is a stretch if there really are no other users. > > This is forward thinking patch :-) > > Other subsystems may create files/directories in proc/sysfs, and should > check for bad names as well: > > /proc/2821/net/dev_snmp6/eth0 > > This looks exactly like something coming from userspace and making it > into /proc, so the filter function doesn't belong to kernel/module/internal.h You mean like: [24180.292204] tuxthe____: renamed from tuxthe???? root@dalek:/home/dg# ls /sys/class/net/ enp5s0 lo tuxthe____ tuxthe???? tuxthe???? virbr0 virbr1 ? Dave > -- -----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/