VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostDnsService.h@ 77863

Last change on this file since 77863 was 77506, checked in by vboxsync, 6 years ago

Main/HostDnsService: fix a use-after-free running VBoxSVC in debug mode.
bugref:9144: AddressSanitizer: heap-use-after-free in VBoxSVC in HostDnsMonitor::pollGlobalExtraData()
This did not trigger during normal usage, but when debugging and keeping
VBoxSVC around it did. The change terminates the Host DNS monitor thread
properly when the VirtualBox object is destroyed, which in normal use also
ends the process.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: HostDnsService.h 77506 2019-02-28 16:25:19Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_SRC_src_server_HostDnsService_h
19#define MAIN_INCLUDED_SRC_src_server_HostDnsService_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23#include "VirtualBoxBase.h"
24
25#include <iprt/err.h> /* VERR_IGNORED */
26#include <iprt/cpp/lock.h>
27
28#include <list>
29#include <vector>
30
31typedef std::list<com::Utf8Str> Utf8StrList;
32typedef Utf8StrList::iterator Utf8StrListIterator;
33
34class HostDnsMonitorProxy;
35typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
36
37class HostDnsInformation
38{
39 public:
40 static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
41 static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
42
43 public:
44 std::vector<std::string> servers;
45 std::string domain;
46 std::vector<std::string> searchList;
47 bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
48};
49
50/**
51 * This class supposed to be a real DNS monitor object it should be singleton,
52 * it lifecycle starts and ends together with VBoxSVC.
53 */
54class HostDnsMonitor
55{
56 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsMonitor);
57
58 public:
59 static HostDnsMonitor *createHostDnsMonitor();
60 void shutdown();
61
62 /* @note: method will wait till client call
63 HostDnsService::monitorThreadInitializationDone() */
64 virtual HRESULT init(HostDnsMonitorProxy *proxy);
65
66 protected:
67 explicit HostDnsMonitor(bool fThreaded = false);
68 virtual ~HostDnsMonitor();
69
70 void setInfo(const HostDnsInformation &);
71
72 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
73 void monitorThreadInitializationDone();
74 virtual void monitorThreadShutdown() = 0;
75 virtual int monitorWorker() = 0;
76
77 private:
78 static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *);
79
80 protected:
81 mutable RTCLockMtx m_LockMtx;
82
83 public:
84 struct Data;
85 Data *m;
86};
87
88/**
89 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
90 */
91class HostDnsMonitorProxy
92{
93 public:
94 HostDnsMonitorProxy();
95 ~HostDnsMonitorProxy();
96 void init(VirtualBox *virtualbox);
97 void uninit();
98 void notify(const HostDnsInformation &info);
99
100 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
101 HRESULT GetDomainName(com::Utf8Str *pDomainName);
102 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
103
104 private:
105 void pollGlobalExtraData();
106 bool updateInfo(const HostDnsInformation &info);
107
108 private:
109 mutable RTCLockMtx m_LockMtx;
110
111 private:
112 struct Data;
113 Data *m;
114};
115
116# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
117class HostDnsServiceDarwin : public HostDnsMonitor
118{
119 public:
120 HostDnsServiceDarwin();
121 ~HostDnsServiceDarwin();
122 virtual HRESULT init(HostDnsMonitorProxy *proxy);
123
124 protected:
125 virtual void monitorThreadShutdown();
126 virtual int monitorWorker();
127
128 private:
129 HRESULT updateInfo();
130 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
131 struct Data;
132 Data *m;
133};
134# endif
135# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
136class HostDnsServiceWin : public HostDnsMonitor
137{
138 public:
139 HostDnsServiceWin();
140 ~HostDnsServiceWin();
141 virtual HRESULT init(HostDnsMonitorProxy *proxy);
142
143 protected:
144 virtual void monitorThreadShutdown();
145 virtual int monitorWorker();
146
147 private:
148 HRESULT updateInfo();
149
150 private:
151 struct Data;
152 Data *m;
153};
154# endif
155# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
156 || defined(DOXYGEN_RUNNING)
157class HostDnsServiceResolvConf: public HostDnsMonitor
158{
159 public:
160 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
161 virtual ~HostDnsServiceResolvConf();
162 virtual HRESULT init(HostDnsMonitorProxy *proxy, const char *aResolvConfFileName);
163 const std::string& resolvConf() const;
164
165 protected:
166 HRESULT readResolvConf();
167 /* While not all hosts supports Hosts DNS change notifiaction
168 * default implementation offers return VERR_IGNORE.
169 */
170 virtual void monitorThreadShutdown() {}
171 virtual int monitorWorker() {return VERR_IGNORED;}
172
173 protected:
174 struct Data;
175 Data *m;
176};
177# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
178/**
179 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
180 */
181class HostDnsServiceSolaris : public HostDnsServiceResolvConf
182{
183 public:
184 HostDnsServiceSolaris(){}
185 ~HostDnsServiceSolaris(){}
186 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
187 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
188 }
189};
190
191# endif
192# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
193class HostDnsServiceLinux : public HostDnsServiceResolvConf
194{
195 public:
196 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
197 virtual ~HostDnsServiceLinux();
198 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
199 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
200 }
201
202 protected:
203 virtual void monitorThreadShutdown();
204 virtual int monitorWorker();
205};
206
207# endif
208# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
209class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
210{
211 public:
212 HostDnsServiceFreebsd(){}
213 ~HostDnsServiceFreebsd(){}
214 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
215 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
216 }
217};
218
219# endif
220# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
221class HostDnsServiceOs2 : public HostDnsServiceResolvConf
222{
223 public:
224 HostDnsServiceOs2(){}
225 ~HostDnsServiceOs2(){}
226 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
227 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
228 return HostDnsServiceResolvConf::init(proxy, "\\MPTN\\ETC\\RESOLV2");
229 }
230};
231
232# endif
233# endif
234
235#endif /* !MAIN_INCLUDED_SRC_src_server_HostDnsService_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette