Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp161480rdb; Thu, 21 Dec 2023 05:56:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9inyxVEEj7i0O4u0LonAHa3xk6JEhpuVWWAEb90StT+Z9Gga1Fc10Z6ANGlNCCQS2mOmC X-Received: by 2002:a17:906:1758:b0:a26:a8b6:7c4b with SMTP id d24-20020a170906175800b00a26a8b67c4bmr252112eje.175.1703167008313; Thu, 21 Dec 2023 05:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703167008; cv=none; d=google.com; s=arc-20160816; b=E+TWnZLh7PIGu6nk4+Xm7VX4cb9gqZZvH7p50SxnIUX+HrQvjeQBdUdYAjztpX/Fsr L/jVJqcir5Bi7vi20hJJQilSUs5SzHPztXo64YVpNuNRaX/g7R/St5zh1dbtvFtGIVHS vWZOobMNyW8EK3kL454891HVeBN7kykb4hFF3CFpcfR5nSsgCY2Tz8NKs9ox7nK/kjL3 ktWsGqB5bD8OcpT/1npe7sdSotBaS4PPBDE3JZYk1gXpNuZupz5rXtDR7ZxVmOTr1CNZ tPxY+2hsJu2wv1NKEyVgvvudLuk8Zwc3p/xe4uH7yW1b9HwS1dXZP2YI7EJzKFGFyPu+ hQSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EH9h86qymwvgZJZioKpFB1S+Jiabzjnf9t3z4SHqXYg=; fh=amlZE/0bmUZb0iruJSnjcNGDWpcpLgWng4o3VdOIeS8=; b=gbeds4B3wmKTTmu9zosjokWZ7Z9ye/58qf4Fc5GqohoVt0JapVUy/XcDH9IoCaima+ AUJkPf5Gn8UlJWQGMpZCFRFPN7OxwDgS01OUVWjmdX6jRuOFMpFlz4/jrZKCWDVXvquD oeKlPJOmpyD08R2vlfwtBF1kfausXCpZZHKXQWd76UocCqjEmQ+gFft6UZXrK3ZAtmYb FhhyDw7N60BcpmzO4w1Hdm3g92PVsA6DaA6GWC6RS+rmBgzd6qWkYrBBCEoBBsYRESXZ Qt0NTxPX55aop4Vxktk5Dvq1neq8WPzR7nLm+XnGXJJ8c7H2KIS2mfyHUsT26Yy1PB1W 2BfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BvUTm1lh; spf=pass (google.com: domain of linux-kernel+bounces-8518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8518-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id am11-20020a170906568b00b00a2354db52e7si869515ejc.937.2023.12.21.05.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 05:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BvUTm1lh; spf=pass (google.com: domain of linux-kernel+bounces-8518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8518-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 14BEC1F22578 for ; Thu, 21 Dec 2023 13:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD09459905; Thu, 21 Dec 2023 13:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BvUTm1lh" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 86AED58224 for ; Thu, 21 Dec 2023 13:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703166370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EH9h86qymwvgZJZioKpFB1S+Jiabzjnf9t3z4SHqXYg=; b=BvUTm1lhxchgJ0lpmtjf03M+Bbj8kO4871VPBBi6niU1kySBabOg6erTYaPZVLrb+6dU5a hMMxGdnij8UYoi27KjtBwD4cY7PUDLPl3r6S211xV2K1WhYL5tg4jvcbSkkUN98wuR+7Kc 3eSxTF/giKErrrbr+0H7jxqpuz70Bpc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-tcseBC5uPc2QPizZ8LT_0g-1; Thu, 21 Dec 2023 08:46:06 -0500 X-MC-Unique: tcseBC5uPc2QPizZ8LT_0g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47ACC3C29A71; Thu, 21 Dec 2023 13:46:05 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08AD3C15968; Thu, 21 Dec 2023 13:46:03 +0000 (UTC) From: David Howells To: Markus Suvanto , Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, keyrings@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] afs: Fix dynamic root lookup DNS check Date: Thu, 21 Dec 2023 13:45:29 +0000 Message-ID: <20231221134558.1659214-3-dhowells@redhat.com> In-Reply-To: <20231221134558.1659214-1-dhowells@redhat.com> References: <20231221134558.1659214-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 In the afs dynamic root directory, the ->lookup() function does a DNS check on the cell being asked for and if the DNS upcall reports an error it will report an error back to userspace (typically ENOENT). However, if a failed DNS upcall returns a new-style result, it will return a valid result, with the status field set appropriately to indicate the type of failure - and in that case, dns_query() doesn't return an error and we let stat() complete with no error - which can cause confusion in userspace as subsequent calls that trigger d_automount then fail with ENOENT. Fix this by checking the status result from a valid dns_query() and returning an error if it indicates a failure. Fixes: bbb4c4323a4d ("dns: Allow the dns resolver to retrieve a server set") Reported-by: Markus Suvanto Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216637 Signed-off-by: David Howells Tested-by: Markus Suvanto cc: Marc Dionne cc: linux-afs@lists.infradead.org --- Notes: Changes ======= ver #2) - Fix signed-unsigned comparison when checking return val. fs/afs/dynroot.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c index 34474a061654..1f656005018e 100644 --- a/fs/afs/dynroot.c +++ b/fs/afs/dynroot.c @@ -114,6 +114,7 @@ static int afs_probe_cell_name(struct dentry *dentry) struct afs_net *net = afs_d2net(dentry); const char *name = dentry->d_name.name; size_t len = dentry->d_name.len; + char *result = NULL; int ret; /* Names prefixed with a dot are R/W mounts. */ @@ -131,9 +132,22 @@ static int afs_probe_cell_name(struct dentry *dentry) } ret = dns_query(net->net, "afsdb", name, len, "srv=1", - NULL, NULL, false); - if (ret == -ENODATA || ret == -ENOKEY) + &result, NULL, false); + if (ret == -ENODATA || ret == -ENOKEY || ret == 0) ret = -ENOENT; + if (ret > 0 && ret >= sizeof(struct dns_server_list_v1_header)) { + struct dns_server_list_v1_header *v1 = (void *)result; + + if (v1->hdr.zero == 0 && + v1->hdr.content == DNS_PAYLOAD_IS_SERVER_LIST && + v1->hdr.version == 1 && + (v1->status != DNS_LOOKUP_GOOD && + v1->status != DNS_LOOKUP_GOOD_WITH_BAD)) + return -ENOENT; + + } + + kfree(result); return ret; }