Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1641640rdb; Sat, 23 Dec 2023 16:03:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAO/HxbLgj7YnYhiUMw1OJNtD//L8TKw3l0osLeOuix5+U22n9LfJRWhnZrOxJaWMC7Xg8 X-Received: by 2002:a05:620a:3721:b0:77f:2645:5b64 with SMTP id de33-20020a05620a372100b0077f26455b64mr4670600qkb.105.1703376194772; Sat, 23 Dec 2023 16:03:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703376194; cv=none; d=google.com; s=arc-20160816; b=boJGkVllGEC+kfQnR9A1hIiWD3Yl6gRN/lzmKnjR4i2kRuDAcsV16fmjI8h2+OsTbc Hv0Ej6nr6Kqnl8DwYXkM3txKZcfjvEhrEhLdf3OgTae6VxKIN73ekdyNilBABS6QybOj yB6xQHG57DI/5ygGGcimIij9sIdgdBRtwCFnwxFhZebx+pp6S+gmK1GGH9MZI6bOiC4d aEWHYKNwnXp+hIDQVEC0Okn0YwD/SL/8lk5ujsp9pxGTk3BA3EmHpEeje1Jgk2ad5yiE qCaitjG3GscSBKOQRDkcaxWf0LGILCgD1PlrAdlZWqT3xAAgou9D2zWhwAyV5gcbDdde gbcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:content-transfer-encoding:content-id:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :references:in-reply-to:from:organization:dkim-signature; bh=f2Rh5CNVsutE5oVr7mjP/qOsDM7D/4ihkvki7rZGwjY=; fh=gyW0lKOVq2pxBzqWXGfsbB4alWFeqbaStyEWxoAoB00=; b=cLNG0KrptgfX0kENVRqZwksqO3J0/RMTBexpSw+LdF+kCP6x3hC+1rM2zeMyis0Jw6 10kQVhiWLMtTN+FYdvtmYlWZqUtvaPAgXqMVX9GwfzUiYKWReyTbg8yieav68o288DZz qz9XS4LrGpLEXofgQUXaXFVYBq4DIqhJR/XUHe+elFOacEIu6WJyeD3816Ib5ScXeSMi z6oVImjzelJ8cxs8tmBl+IW7EMV7hH3fwXUOGMmUrQQ3hRSHgOGYWNAaK87dsfDdaUv8 sImc/rfikTWSjHgpWv9u579yOqK0WujqU6bYVisS1sk4L6bo/R4iIiNtZ/13qq+rbU2s Vk2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WGMishtg; spf=pass (google.com: domain of linux-nfs+bounces-788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bs11-20020a05620a470b00b0077f445f685dsi3238501qkb.656.2023.12.23.16.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 16:03:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WGMishtg; spf=pass (google.com: domain of linux-nfs+bounces-788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-788-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7500E1C214BF for ; Sun, 24 Dec 2023 00:03:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C10E119B; Sun, 24 Dec 2023 00:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WGMishtg" X-Original-To: linux-nfs@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 9B69B20307 for ; Sun, 24 Dec 2023 00:02:58 +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=1703376177; 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=f2Rh5CNVsutE5oVr7mjP/qOsDM7D/4ihkvki7rZGwjY=; b=WGMishtg4wQPnAedYPiXVRNdOpnX3xfOtDpyS3lD6Ygvk4gn6JbVK7oEzWgYP90TsnlbLF 0IL/zoS1U7Nd6k6fcNVUg3IbGR4kjSAHnHLdRavtBc/kuEourmIewSCsXdfZoYa4FAx69z JdcaBjtT3S1KqErwvsFi/5B4PyJuSrU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-R6RYiUWMPziAVk9Kh69GVQ-1; Sat, 23 Dec 2023 19:02:54 -0500 X-MC-Unique: R6RYiUWMPziAVk9Kh69GVQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 4C5D1803915; Sun, 24 Dec 2023 00:02:53 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5D7E3C25; Sun, 24 Dec 2023 00:02:49 +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 From: David Howells In-Reply-To: References: <1843374.1703172614@warthog.procyon.org.uk> <20231223172858.GI201037@kernel.org> To: Linus Torvalds , Edward Adam Davis Cc: dhowells@redhat.com, Simon Horman , Markus Suvanto , Jeffrey E Altman , Marc Dionne , Wang Lei , Jeff Layton , Steve French , Jarkko Sakkinen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-afs@lists.infradead.org, keyrings@vger.kernel.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] keys, dns: Fix missing size check of V1 server-list header Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2592944.1703376169.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Sun, 24 Dec 2023 00:02:49 +0000 Message-ID: <2592945.1703376169@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Hi Linus, Edward, Here's Linus's patch dressed up with a commit message. I would marginally prefer just to insert the missing size check, but I'm also fine with Linus= 's approach for now until we have different content types or newer versions. Note that I'm not sure whether I should require Linus's S-o-b since he mad= e modifications or whether I should use a Codeveloped-by line for him. David --- From: Edward Adam Davis keys, dns: Fix missing size check of V1 server-list header The dns_resolver_preparse() function has a check on the size of the payloa= d for the basic header of the binary-style payload, but is missing a check for the size of the V1 server-list payload header after determining that's what we've been given. Fix this by getting rid of the the pointer to the basic header and just assuming that we have a V1 server-list payload and moving the V1 server list pointer inside the if-statement. Dealing with other types and versions can be left for when such have been defined. This can be tested by doing the following with KASAN enabled: echo -n -e '\x0\x0\x1\x2' | keyctl padd dns_resolver foo @p and produces an oops like the following: BUG: KASAN: slab-out-of-bounds in dns_resolver_preparse+0xc9f/0xd6= 0 net/dns_resolver/dns_key.c:127 Read of size 1 at addr ffff888028894084 by task syz-executor265/50= 69 ... Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:377 [inline] print_report+0xc3/0x620 mm/kasan/report.c:488 kasan_report+0xd9/0x110 mm/kasan/report.c:601 dns_resolver_preparse+0xc9f/0xd60 net/dns_resolver/dns_key.c:127 __key_create_or_update+0x453/0xdf0 security/keys/key.c:842 key_create_or_update+0x42/0x50 security/keys/key.c:1007 __do_sys_add_key+0x29c/0x450 security/keys/keyctl.c:134 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0x40/0x110 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x62/0x6a This patch was originally by Edward Adam Davis, but was modified by Linus. Fixes: b946001d3bb1 ("keys, dns: Allow key types (eg. DNS) to be reclaimed= immediately on expiry") Reported-and-tested-by: syzbot+94bbb75204a05da3d89f@syzkaller.appspotmail.= com Link: https://lore.kernel.org/r/0000000000009b39bc060c73e209@google.com/ Suggested-by: Linus Torvalds Signed-off-by: Edward Adam Davis Signed-off-by: David Howells Tested-by: David Howells cc: Edward Adam Davis cc: Simon Horman cc: Linus Torvalds cc: Jarkko Sakkinen cc: Jeffrey E Altman cc: Wang Lei cc: Jeff Layton cc: Steve French cc: Marc Dionne cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: linux-afs@lists.infradead.org cc: linux-cifs@vger.kernel.org cc: linux-nfs@vger.kernel.org cc: ceph-devel@vger.kernel.org cc: keyrings@vger.kernel.org cc: netdev@vger.kernel.org --- net/dns_resolver/dns_key.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c index 2a6d363763a2..f18ca02aa95a 100644 --- a/net/dns_resolver/dns_key.c +++ b/net/dns_resolver/dns_key.c @@ -91,8 +91,6 @@ const struct cred *dns_resolver_cache; static int dns_resolver_preparse(struct key_preparsed_payload *prep) { - const struct dns_server_list_v1_header *v1; - const struct dns_payload_header *bin; struct user_key_payload *upayload; unsigned long derrno; int ret; @@ -103,27 +101,28 @@ dns_resolver_preparse(struct key_preparsed_payload *= prep) return -EINVAL; = if (data[0] =3D=3D 0) { + const struct dns_server_list_v1_header *v1; + /* It may be a server list. */ - if (datalen <=3D sizeof(*bin)) + if (datalen <=3D sizeof(*v1)) return -EINVAL; = - bin =3D (const struct dns_payload_header *)data; - kenter("[%u,%u],%u", bin->content, bin->version, datalen); - if (bin->content !=3D DNS_PAYLOAD_IS_SERVER_LIST) { + v1 =3D (const struct dns_server_list_v1_header *)data; + kenter("[%u,%u],%u", v1->hdr.content, v1->hdr.version, datalen); + if (v1->hdr.content !=3D DNS_PAYLOAD_IS_SERVER_LIST) { pr_warn_ratelimited( "dns_resolver: Unsupported content type (%u)\n", - bin->content); + v1->hdr.content); return -EINVAL; } = - if (bin->version !=3D 1) { + if (v1->hdr.version !=3D 1) { pr_warn_ratelimited( "dns_resolver: Unsupported server list version (%u)\n", - bin->version); + v1->hdr.version); return -EINVAL; } = - v1 =3D (const struct dns_server_list_v1_header *)bin; if ((v1->status !=3D DNS_LOOKUP_GOOD && v1->status !=3D DNS_LOOKUP_GOOD_WITH_BAD)) { if (prep->expiry =3D=3D TIME64_MAX)