blob: add4d59a99a5ff4ef040ae44659a5e8721230cf6 [file] [log] [blame]
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +02001.. SPDX-License-Identifier: GPL-2.0
Wang Lei1a4240f2010-08-04 15:16:33 +01002
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +02003===================
4DNS Resolver Module
5===================
6
7.. Contents:
Wang Lei1a4240f2010-08-04 15:16:33 +01008
9 - Overview.
10 - Compilation.
11 - Setting up.
12 - Usage.
13 - Mechanism.
14 - Debugging.
15
16
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020017Overview
Wang Lei1a4240f2010-08-04 15:16:33 +010018========
19
20The DNS resolver module provides a way for kernel services to make DNS queries
21by way of requesting a key of key type dns_resolver. These queries are
22upcalled to userspace through /sbin/request-key.
23
24These routines must be supported by userspace tools dns.upcall, cifs.upcall and
25request-key. It is under development and does not yet provide the full feature
26set. The features it does support include:
27
28 (*) Implements the dns_resolver key_type to contact userspace.
29
30It does not yet support the following AFS features:
31
32 (*) Dns query support for AFSDB resource record.
33
34This code is extracted from the CIFS filesystem.
35
36
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020037Compilation
Wang Lei1a4240f2010-08-04 15:16:33 +010038===========
39
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020040The module should be enabled by turning on the kernel configuration options::
Wang Lei1a4240f2010-08-04 15:16:33 +010041
42 CONFIG_DNS_RESOLVER - tristate "DNS Resolver support"
43
44
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020045Setting up
Wang Lei1a4240f2010-08-04 15:16:33 +010046==========
47
48To set up this facility, the /etc/request-key.conf file must be altered so that
49/sbin/request-key can appropriately direct the upcalls. For example, to handle
50basic dname to IPv4/IPv6 address resolution, the following line should be
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020051added::
52
Wang Lei1a4240f2010-08-04 15:16:33 +010053
54 #OP TYPE DESC CO-INFO PROGRAM ARG1 ARG2 ARG3 ...
55 #====== ============ ======= ======= ==========================
56 create dns_resolver * * /usr/sbin/cifs.upcall %k
57
58To direct a query for query type 'foo', a line of the following should be added
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020059before the more general line given above as the first match is the one taken::
Wang Lei1a4240f2010-08-04 15:16:33 +010060
61 create dns_resolver foo:* * /usr/sbin/dns.foo %k
62
63
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020064Usage
Wang Lei1a4240f2010-08-04 15:16:33 +010065=====
66
67To make use of this facility, one of the following functions that are
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020068implemented in the module can be called after doing::
Wang Lei1a4240f2010-08-04 15:16:33 +010069
70 #include <linux/dns_resolver.h>
71
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020072 ::
73
74 int dns_query(const char *type, const char *name, size_t namelen,
75 const char *options, char **_result, time_t *_expiry);
Wang Lei1a4240f2010-08-04 15:16:33 +010076
77 This is the basic access function. It looks for a cached DNS query and if
78 it doesn't find it, it upcalls to userspace to make a new DNS query, which
79 may then be cached. The key description is constructed as a string of the
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +020080 form::
Wang Lei1a4240f2010-08-04 15:16:33 +010081
82 [<type>:]<name>
83
84 where <type> optionally specifies the particular upcall program to invoke,
85 and thus the type of query to do, and <name> specifies the string to be
86 looked up. The default query type is a straight hostname to IP address
87 set lookup.
88
89 The name parameter is not required to be a NUL-terminated string, and its
90 length should be given by the namelen argument.
91
92 The options parameter may be NULL or it may be a set of options
93 appropriate to the query type.
94
95 The return value is a string appropriate to the query type. For instance,
96 for the default query type it is just a list of comma-separated IPv4 and
97 IPv6 addresses. The caller must free the result.
98
David Howellsff9517a2010-08-06 03:13:52 +010099 The length of the result string is returned on success, and a negative
100 error code is returned otherwise. -EKEYREJECTED will be returned if the
101 DNS lookup failed.
Wang Lei1a4240f2010-08-04 15:16:33 +0100102
103 If _expiry is non-NULL, the expiry time (TTL) of the result will be
104 returned also.
105
David Howells700920e2012-01-18 15:31:45 +0000106The kernel maintains an internal keyring in which it caches looked up keys.
107This can be cleared by any process that has the CAP_SYS_ADMIN capability by
108the use of KEYCTL_KEYRING_CLEAR on the keyring ID.
109
Wang Lei1a4240f2010-08-04 15:16:33 +0100110
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +0200111Reading DNS Keys from Userspace
David Howells1362fa02011-03-03 11:28:58 +0000112===============================
113
114Keys of dns_resolver type can be read from userspace using keyctl_read() or
115"keyctl read/print/pipe".
116
117
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +0200118Mechanism
Wang Lei1a4240f2010-08-04 15:16:33 +0100119=========
120
121The dnsresolver module registers a key type called "dns_resolver". Keys of
122this type are used to transport and cache DNS lookup results from userspace.
123
124When dns_query() is invoked, it calls request_key() to search the local
125keyrings for a cached DNS result. If that fails to find one, it upcalls to
126userspace to get a new result.
127
128Upcalls to userspace are made through the request_key() upcall vector, and are
129directed by means of configuration lines in /etc/request-key.conf that tell
130/sbin/request-key what program to run to instantiate the key.
131
132The upcall handler program is responsible for querying the DNS, processing the
133result into a form suitable for passing to the keyctl_instantiate_key()
134routine. This then passes the data to dns_resolver_instantiate() which strips
135off and processes any options included in the data, and then attaches the
136remainder of the string to the key as its payload.
137
138The upcall handler program should set the expiry time on the key to that of the
139lowest TTL of all the records it has extracted a result from. This means that
140the key will be discarded and recreated when the data it holds has expired.
141
142dns_query() returns a copy of the value attached to the key, or an error if
143that is indicated instead.
144
Kees Cook3db38ed2017-05-13 04:51:52 -0700145See <file:Documentation/security/keys/request-key.rst> for further
Randy Dunlapd410fa42011-05-19 15:59:38 -0700146information about request-key function.
Wang Lei1a4240f2010-08-04 15:16:33 +0100147
148
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +0200149Debugging
Wang Lei1a4240f2010-08-04 15:16:33 +0100150=========
151
152Debugging messages can be turned on dynamically by writing a 1 into the
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +0200153following file::
Wang Lei1a4240f2010-08-04 15:16:33 +0100154
Mauro Carvalho Chehab9dfe1362020-04-28 00:01:32 +0200155 /sys/module/dnsresolver/parameters/debug