Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp378495pxf; Thu, 11 Mar 2021 06:12:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3jiVEsjWCHbX4guhOnWxryRiBpX5pH4tjqwPYWqQpd4xONMiLpbphUeVHmfJKW0XmdoHh X-Received: by 2002:a17:906:3b99:: with SMTP id u25mr3245149ejf.277.1615471945519; Thu, 11 Mar 2021 06:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615471945; cv=none; d=google.com; s=arc-20160816; b=A4Pr2QaL8jenz0jFawgFmacDNGO4VkMkWGg++nZzX7wYhTRThYk9g4/kLkik9R7xJz RPPIomTwJBaQXJ4VfuS+AZlwvsU9k++cSPGBMo21Q0+RIkwpFQbjG7Co740x6x9GsXPs dfFTJ3g75NiEHA1YH3KDz7R1Lbf67W6PVrXSSTLo6oMVBxR8CeTwj5OsUrKgxe+i+ESx hR5qO+hDjXYAzbFwZZCB6m7oQ1aa3RrQyULiAKVS5lW7fD/YWy7pNCvt37munu0hJ7vO cd9rSE7yxr4rICCTkrbPE4KE3ZoHDhYLDAV3Ml1LUUmHuoMYP5QwFoj6WlJ7Ad8e0n9W Kw8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=Sa6wetqoaJXD5avPHDgES9Xzvvsmx+M+iS9y4Mh8zBg=; b=PIfYGlISp2Xju7Bv+5E+M1Jujxtp5KBXYdnsOOqilG65kPMHzjUNJcXnC0qTTRM0J5 tFzaTm1MTuqqlhY2MqrAtvFYduQsc4WRS3VNk4kakx7jmwa6sSVaBD+Rnu2LaLrd4DtY gwxZEQCgqdkjUfrG4oDU2d+vUZiBZCO5xo5gbnb2+faZPo5SRhXDqUnyGuaaxajmOaFB +nDoanIgYZwocDAEjEOLmjKGF/MR1yfcUOw4GY8zxmnTb2aQ6EOEk0cDahTu3AuQHcZ3 XNeOJAH/UwVa6B90Zf+1R/8Mbk25YA4qj9SA+9/G8C5GR6slP+HyX1W8RJL40NXVjO2Y KMuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hpLvQB1/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb10si1857331ejc.273.2021.03.11.06.12.02; Thu, 11 Mar 2021 06:12:25 -0800 (PST) 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=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hpLvQB1/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233318AbhCKOLC (ORCPT + 99 others); Thu, 11 Mar 2021 09:11:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34564 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233232AbhCKOK3 (ORCPT ); Thu, 11 Mar 2021 09:10:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615471828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sa6wetqoaJXD5avPHDgES9Xzvvsmx+M+iS9y4Mh8zBg=; b=hpLvQB1/Fx7bDYi75dHRwvj3p6rAktKYq/D9sLpuTXCjuHCALfqpRHKzr9MSXoHnMP6YAQ vYniCAZRQrNhLHHN5B1hq+gvbF3S+yk7DMU0xYF0Tej6JWEI04eHRs11tvX7AXorOzlvY1 hd+rFG1oqh3Lqt9fYhZFDPCQoBPDElM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-130-rjxqRl4AOauHMjMLtKKV-Q-1; Thu, 11 Mar 2021 09:10:26 -0500 X-MC-Unique: rjxqRl4AOauHMjMLtKKV-Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8314801817; Thu, 11 Mar 2021 14:10:24 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE1A7196E3; Thu, 11 Mar 2021 14:10:23 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/2] afs: Fix accessing YFS xattrs on a non-YFS server From: David Howells To: linux-afs@lists.infradead.org Cc: Gaja Sophie Peters , Gaja Sophie Peters , dhowells@redhat.com, Gaja Sophie Peters , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 11 Mar 2021 14:10:22 +0000 Message-ID: <161547182293.1868820.9860274141056722598.stgit@warthog.procyon.org.uk> In-Reply-To: <161547181530.1868820.12933722592029066752.stgit@warthog.procyon.org.uk> References: <161547181530.1868820.12933722592029066752.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If someone attempts to access YFS-related xattrs (e.g. afs.yfs.acl) on a file on a non-YFS AFS server (such as OpenAFS), then the kernel will jump to a NULL function pointer because the afs_fetch_acl_operation descriptor doesn't point to a function for issuing an operation on a non-YFS server[1]. Fix this by making afs_wait_for_operation() check that the issue_afs_rpc method is set before jumping to it and setting -ENOTSUPP if not. This fix also covers other potential operations that also only exist on YFS servers. afs_xattr_get/set_yfs() then need to translate -ENOTSUPP to -ENODATA as the former error is internal to the kernel. The bug shows up as an oops like the following: BUG: kernel NULL pointer dereference, address: 0000000000000000 [...] Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6. [...] Call Trace: afs_wait_for_operation+0x83/0x1b0 [kafs] afs_xattr_get_yfs+0xe6/0x270 [kafs] __vfs_getxattr+0x59/0x80 vfs_getxattr+0x11c/0x140 getxattr+0x181/0x250 ? __check_object_size+0x13f/0x150 ? __fput+0x16d/0x250 __x64_sys_fgetxattr+0x64/0xb0 do_syscall_64+0x49/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7fb120a9defe This was triggered with "cp -a" which attempts to copy xattrs, including afs ones, but is easier to reproduce with getfattr, e.g.: getfattr -d -m ".*" /afs/openafs.org/ Fixes: e49c7b2f6de7 ("afs: Build an abstraction around an "operation" concept") Reported-by: Gaja Sophie Peters Signed-off-by: David Howells Tested-by: Gaja Sophie Peters cc: linux-afs@lists.infradead.org Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003498.html [1] --- fs/afs/fs_operation.c | 7 +++++-- fs/afs/xattr.c | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 97cab12b0a6c..71c58723763d 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -181,10 +181,13 @@ void afs_wait_for_operation(struct afs_operation *op) if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags) && op->ops->issue_yfs_rpc) op->ops->issue_yfs_rpc(op); - else + else if (op->ops->issue_afs_rpc) op->ops->issue_afs_rpc(op); + else + op->ac.error = -ENOTSUPP; - op->error = afs_wait_for_call_to_complete(op->call, &op->ac); + if (op->call) + op->error = afs_wait_for_call_to_complete(op->call, &op->ac); } switch (op->error) { diff --git a/fs/afs/xattr.c b/fs/afs/xattr.c index c629caae5002..4934e325a14a 100644 --- a/fs/afs/xattr.c +++ b/fs/afs/xattr.c @@ -231,6 +231,8 @@ static int afs_xattr_get_yfs(const struct xattr_handler *handler, else ret = -ERANGE; } + } else if (ret == -ENOTSUPP) { + ret = -ENODATA; } error_yacl: @@ -256,6 +258,7 @@ static int afs_xattr_set_yfs(const struct xattr_handler *handler, { struct afs_operation *op; struct afs_vnode *vnode = AFS_FS_I(inode); + int ret; if (flags == XATTR_CREATE || strcmp(name, "acl") != 0) @@ -270,7 +273,10 @@ static int afs_xattr_set_yfs(const struct xattr_handler *handler, return afs_put_operation(op); op->ops = &yfs_store_opaque_acl2_operation; - return afs_do_sync_operation(op); + ret = afs_do_sync_operation(op); + if (ret == -ENOTSUPP) + ret = -ENODATA; + return ret; } static const struct xattr_handler afs_xattr_yfs_handler = {