Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3403653pxf; Mon, 22 Mar 2021 05:47:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHQpWMqcvvfKEZsa1TrnKGSnzDtyHfTE+5jbIdacXv2YokUlCn/HIHqkTHaoMroxPlL5NK X-Received: by 2002:aa7:dc49:: with SMTP id g9mr24972109edu.60.1616417254573; Mon, 22 Mar 2021 05:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616417254; cv=none; d=google.com; s=arc-20160816; b=FGpnSVqGOCbnXVfAAvJhh1NWovy1HH0N1qFil6I9OGZwW9Y8hl/2VUNfirLdU2g1tF bnWw81VEAuq8BhOWsBt9MxJISfdBwJvPA6V3+bY5UdNpKvXS+R4+HcYu56POJY9uaijq tHYN3t1DSAgXD52JTQHIN57kp6lNvyP3zdRBZ5mLSDvW24pZ0UjuX6GUFyA9i6kyjPch o9fLidmoehCp12BUzIXnSMbspYe0zkqLkYl7tF3v+1CHwYER39XL8Rg/0jxnqX5FSvov 4e7shhcaqUr4avwHKiLNpAbg7mmhidVown2c2CdqGGuE/GWwiqI1Cb6UkJIoEOcpmUq1 G5WQ== 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:subject:cc:to :from:dkim-signature; bh=Hfmm+yp2sNaMnqHSCGJDfxYSX2iWvhtmAW92jO+L1AI=; b=IcCqzDZbHW5e5G3u6jzI5GV4DMm65MFGtR4+lLO24AbhLZN0zdfxN0+xPQUr+FWRNL lC1y08vRdyvhU6wBAvLGFOqVwZB34AheeAhYUIm5EKkr5QAsi9PfOHvvjBbN6qXpqG3K wRf1K4HmhPEgvh45E8hJ7TW29lBeyOunLQPyBx2OGjC0aO/czClJTeVIA/7ifn88tsv+ X6ADvfqis/HAh7BnechgNszAhpnjBzDE0HxZbAoXdDZfdrG1s0JXJ1iEh5cSXm38qJZr dqSFrriY1ynTyjgFW7Psb1cSCG1/m+fj43dPmyGXQ2v6dkiJuWC9UffITZ+or/PHknHv dhog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vVMfE0D3; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si11507221edj.284.2021.03.22.05.47.12; Mon, 22 Mar 2021 05:47:34 -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=pass header.i=@linuxfoundation.org header.s=korg header.b=vVMfE0D3; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231435AbhCVMqU (ORCPT + 99 others); Mon, 22 Mar 2021 08:46:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:34112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbhCVMiZ (ORCPT ); Mon, 22 Mar 2021 08:38:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 83E15619B2; Mon, 22 Mar 2021 12:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416652; bh=3iSwuQS17vR/pELboJm0Hl9EfUZ6e7jum/23SXCimB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vVMfE0D32PwWbk2ydbrjFwYD5SWYll00rFRMG4Dylt7ekGSgEaoQji6a/LD7ae+Oi 9/AZ6pC4qZYzXYKZfwOkcWnxW9P7/pkRX9s9VyBdi4sbvD2X5A8q69top0kUAi/nJE vCY4fLc9Cz4RXWUHCA1S+7IB4PLJHWAyju89ICgY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gaja Sophie Peters , David Howells , Marc Dionne , Jeffrey Altman , linux-afs@lists.infradead.org Subject: [PATCH 5.10 033/157] afs: Fix accessing YFS xattrs on a non-YFS server Date: Mon, 22 Mar 2021 13:26:30 +0100 Message-Id: <20210322121934.812515367@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121933.746237845@linuxfoundation.org> References: <20210322121933.746237845@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells commit 64fcbb6158ecc684d84c64424830a9c37c77c5b9 upstream. 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 Reviewed-by: Marc Dionne Reviewed-by: Jeffrey Altman cc: linux-afs@lists.infradead.org Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003498.html [1] Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003566.html # v1 Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003572.html # v2 Signed-off-by: Greg Kroah-Hartman --- fs/afs/fs_operation.c | 7 +++++-- fs/afs/xattr.c | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -181,10 +181,13 @@ void afs_wait_for_operation(struct afs_o 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) { --- a/fs/afs/xattr.c +++ b/fs/afs/xattr.c @@ -230,6 +230,8 @@ static int afs_xattr_get_yfs(const struc else ret = -ERANGE; } + } else if (ret == -ENOTSUPP) { + ret = -ENODATA; } error_yacl: @@ -254,6 +256,7 @@ static int afs_xattr_set_yfs(const struc { struct afs_operation *op; struct afs_vnode *vnode = AFS_FS_I(inode); + int ret; if (flags == XATTR_CREATE || strcmp(name, "acl") != 0) @@ -268,7 +271,10 @@ static int afs_xattr_set_yfs(const struc 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 = {