Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1978852ybh; Tue, 14 Jul 2020 12:09:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycAccIw4MMZ/Gr/W+JnfxHsehpyuNwPS4cRfB4tk2otUfyh4gw2cK5C3vDb7hAlqijmcfC X-Received: by 2002:a17:906:c56:: with SMTP id t22mr6229656ejf.50.1594753772084; Tue, 14 Jul 2020 12:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753772; cv=none; d=google.com; s=arc-20160816; b=covFXLQAZX+xixOzkM6kllPXll6G9tnSiU8jiF16NQbP/L/Ou9BtuQoycyK0Ogcdpl rV+xde28PW8+3SMwoyelM0LrnvegsQRgPwRdkTMU5B+FeqNtGmL0+tp+QWIpYsoCVAXv ZN6MtkaLTvPc8RxkpTovflptQhXZ5iZyoN9UQ/XK2EvQTdZKof0Nj+eIMmLh3kuUUjNJ kE2QI+kdVKGPgsGW5ftIt5DEiVFsZrBvGQsWRGjEsgXWKyM9jNLNsKWF5ULY4xLczWWh cRHcYrFfSAx9N1xgzVgV2zRCXKMqQb3Xh+hTfGW0ShK3UgSOBEob04UgEtQM8E9anfLM NDTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SfNmnpeIaLgqLHElMoiTdMHjuz+bhccYioCzBmt8Vg0=; b=wKT3IrhYZnKrBLT5gM0gHu/Bm1oJl8mwhRaNO4L0/w6Ih7vd9/1pcDZDgAVA3Uk2w/ UrDudaaWalOKJ3sH3ZNCWj4h2HrrdGX2SA0IYNCx1/39vE//iCSZYCkh0E07vsZKSXFB OBjpITLgV8aYfG9s5zbpS/ZNmJ9C76MXfcPDHXuYH5iS7dL0Fjcmh2c/gk9jODS6WnPq /0eCAhMBikO+u3nB8c1UK/w2FE8tyTv1NahU2glnLu2K7/LV61EBxy/Gxp7gsQPeMKVc YJNdovB8L4BVZukDMYE5wmlee7hqKVIy7Wad1zPonj46pJgzgEZCmyNdSjquam8wdlCi k28w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=DqW4FLzT; 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 t22si12339949edy.39.2020.07.14.12.09.08; Tue, 14 Jul 2020 12:09:32 -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; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=DqW4FLzT; 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 S1731312AbgGNTJG (ORCPT + 99 others); Tue, 14 Jul 2020 15:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729587AbgGNTIv (ORCPT ); Tue, 14 Jul 2020 15:08:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B915AC061755; Tue, 14 Jul 2020 12:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=SfNmnpeIaLgqLHElMoiTdMHjuz+bhccYioCzBmt8Vg0=; b=DqW4FLzTD57cZNh10SjFknXCtC Mow05kCJ7Q/oZx3rGuN9I6SEx6li24QLIAE1xENr/zk9CRUI6iz4sASvq7zTG0ogSZNxgT/Espl9a g9/6+KSWPSOZ+w543FqtOfDsK+dJvdFJXQKFNsQq5SQqWou1MA0MLXlAq0Lxie7T82TGd3C/nsPhk zknezzp02cXSyZO0Sw1eSvA2GAvs7ULLHpfxBhTvgEYlh8AIMl4iYPiLbXouw7KkVO/KPU/JzE1hZ bTzzNK8weW1KPOFzo9M5OQuGG/9I5Z90bvSUTYx3E4i4Y/73nZzw9MbrjcvRBtjDKVRTRE77NDRDw 4ck54ujg==; Received: from 089144201169.atnat0010.highway.a1.net ([89.144.201.169] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvQIM-0005pB-0o; Tue, 14 Jul 2020 19:08:50 +0000 From: Christoph Hellwig To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Song Liu , Al Viro , Linus Torvalds , linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/23] fs: add a vfs_fchown helper Date: Tue, 14 Jul 2020 21:04:05 +0200 Message-Id: <20200714190427.4332-2-hch@lst.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714190427.4332-1-hch@lst.de> References: <20200714190427.4332-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper for struct file based chown operations. To be used by the initramfs code soon. Signed-off-by: Christoph Hellwig --- fs/open.c | 29 +++++++++++++++++------------ include/linux/fs.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/fs/open.c b/fs/open.c index 6cd48a61cda3b9..103c66309bee67 100644 --- a/fs/open.c +++ b/fs/open.c @@ -740,23 +740,28 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group AT_SYMLINK_NOFOLLOW); } +int vfs_fchown(struct file *file, uid_t user, gid_t group) +{ + int error; + + error = mnt_want_write_file(file); + if (error) + return error; + audit_file(file); + error = chown_common(&file->f_path, user, group); + mnt_drop_write_file(file); + return error; +} + int ksys_fchown(unsigned int fd, uid_t user, gid_t group) { struct fd f = fdget(fd); int error = -EBADF; - if (!f.file) - goto out; - - error = mnt_want_write_file(f.file); - if (error) - goto out_fput; - audit_file(f.file); - error = chown_common(&f.file->f_path, user, group); - mnt_drop_write_file(f.file); -out_fput: - fdput(f); -out: + if (f.file) { + error = vfs_fchown(f.file, user, group); + fdput(f); + } return error; } diff --git a/include/linux/fs.h b/include/linux/fs.h index f5abba86107d86..0ddd64ca0b45c0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1744,6 +1744,8 @@ int vfs_mkobj(struct dentry *, umode_t, int (*f)(struct dentry *, umode_t, void *), void *); +int vfs_fchown(struct file *file, uid_t user, gid_t group); + extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); #ifdef CONFIG_COMPAT -- 2.27.0