From owner-freebsd-net@freebsd.org Fri Jan 8 17:58:36 2021 Return-Path: Delivered-To: freebsd-net@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1AFA84D150A for ; Fri, 8 Jan 2021 17:58:36 +0000 (UTC) (envelope-from shamaz.mazum@gmail.com) Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DC9nl31qVz4kdx; Fri, 8 Jan 2021 17:58:35 +0000 (UTC) (envelope-from shamaz.mazum@gmail.com) Received: by mail-oi1-x22f.google.com with SMTP id q205so12195947oig.13; Fri, 08 Jan 2021 09:58:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=twbiF7iw+NszQGx/EsvRdo+QIW475NjEuUohx/QD1iU=; b=TEjkY3IdSK0xrPrJ4q4lvgAiKZgIxxL0h15ju1/vBsDkhicc5ivHJr5/CTz2qPg9Iu ubl9PqtkVqQF1YxxmL9BHkya9XXqVtIyBDUw2DK0yeS1T5qZxV6X2v0Ksx+hOsmNDTru JL/umUEhk6hYKOdNp6n9HCV4e4B7XciXCL0dQBxiLmbc5kyZO6Sz/A3foV4AUqOCnnwe Lv7rhPqsaJx6q8eJihpjNHeL5ZJVVs8cWYcvnaFNXzh5Xp05/sdadjBZjP735XwNQIul JJwHRRF4wtqF6bG5LtRHNzrm/7hBbo+ZJWx7FwfmTCkLXcnLMzQMPLTgiwk1o7y7W4+T KyVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=twbiF7iw+NszQGx/EsvRdo+QIW475NjEuUohx/QD1iU=; b=potXJDHdShQiYT6DfHgq23Urx3d55FUViEkZlkkq7wpJLX8acqINwAXXm6d/P7N85A /ugyHDGiftCZTKeSmzMN8E8EyYICMioDPiRYnw1AhpskC0xxVpOeVTJDV4m167PE0KwZ y4EFq3rc0cfDuihknqVY5AErMQwwCGKT8xVbAhtkrgIYEtAyZTq3+I7VqXTKKWUk02VD PUUFZsNWHwCfGSkCRrVKMwJcINTB6rdLCDcMn1TbCOiIfqpLcZqWHBFWxr8dOqwvJiqZ PTWBcOr/I1xinm2j4cgPPBEo67zZm5PPnbE5p3DlpLLaITeLW6KNryf8sYyNq825cbFw rARA== X-Gm-Message-State: AOAM531q0sPU08Ezs6iwY4BeFu+WBMdHnLjRp8WeH3F/jVhwByo1/j+R DBfozM7qBKYNvvbUo/PVvsW3DPIYBgb5fjiRa6pknlUSRCiWpA== X-Google-Smtp-Source: ABdhPJx1zhmsah1Yg6eBQBC7WzXyLTXfenIZQol2oAjZJpju7tb7xUJe0HF390n6i6v/cWbrCjtDgPQ9ezVMBXjWqpo= X-Received: by 2002:a54:400e:: with SMTP id x14mr3139136oie.21.1610128714449; Fri, 08 Jan 2021 09:58:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Vasily Postnicov Date: Fri, 8 Jan 2021 20:58:22 +0300 Message-ID: Subject: Re: DNS using Name Service Switch module and Casper To: Mark Johnston Cc: freebsd-net@freebsd.org X-Rspamd-Queue-Id: 4DC9nl31qVz4kdx X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=TEjkY3Id; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of shamazmazum@gmail.com designates 2607:f8b0:4864:20::22f as permitted sender) smtp.mailfrom=shamazmazum@gmail.com X-Spamd-Result: default: False [-0.01 / 15.00]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RBL_DBL_DONT_QUERY_IPS(0.00)[2607:f8b0:4864:20::22f:from]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(0.99)[0.995]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; SPAMHAUS_ZRD(0.00)[2607:f8b0:4864:20::22f:from:127.0.2.255]; NEURAL_SPAM_LONG(1.00)[1.000]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::22f:from]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-net] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2021 17:58:36 -0000 Nevermind my last question. ZeroMQ is written on C++. Here is shown how you can execute everything with almost empty main. https://stackoverflow.com/questions/38717534/how-do-i-start-a-c-thread-at-p= rogram-startup For C the only way is to use __attribute__((constructor)) AFAIK =D0=BF=D1=82, 8 =D1=8F=D0=BD=D0=B2. 2021 =D0=B3., 20:17 Vasily Postnicov : > I have noticed that after I kill stuck ping, the process spawned with > cap_init() remains. I cannot even kill it with SIGKILL. This is the > output of procstat on such a process. > > > vasily 969 0.0 0.1 26428 6532 v0 I 22:43 0:00.00 ping > vonbraun.local > vasily 983 0.0 0.1 26428 6532 v0 I 22:43 0:00.00 ping > resurrected.local > vasily 1024 0.0 0.1 26428 6532 v0 I 22:49 0:00.00 ping > resurrected.local > vasily 1028 0.0 0.1 26428 6532 v0 I 22:49 0:00.00 ping > resurrected.local > root 1089 0.0 0.0 12976 2512 v1 S+ 22:58 0:00.01 grep pin= g > PID TID COMM TDNAME KSTACK > 1028 100579 ping - mi_switch+0x155 > sleepq_switch+0x109 sleepq_catch_signals+0x266 sleepq_wait_sig+0x9 > _sleep+0x2aa umtxq_sleep+0x19e do_lock_umutex+0x744 > __umtx_op_wait_umutex+0x49 sys__umtx_op+0x7a amd64_syscall+0x12e > fast_syscall_common+0xf8 > > I checked ZeroMQ on which my NSS module is based. It does not use > pthread_atfork(), but uses lots of other unusual pthread functions, > like pthread_setaffinity_np() or pthread_setschedparam(). Do not know > if it matters. Also I do not quite understand when the code in my > module is executed. It should be executed after the capsicumized > sandbox is created, should it not? And I got hang in the process of > creating the sandbox. So I do not understand how my code affects this > process :) > > > =D0=BF=D1=82, 8 =D1=8F=D0=BD=D0=B2. 2021 =D0=B3. =D0=B2 18:45, Mark Johns= ton : > > > > On Wed, Jan 06, 2021 at 07:08:14PM +0300, Vasily Postnicov wrote: > > > That's what I found. > > > > > > At first, ping calls cap_init() in capdns_setup(). cap_init() forks a > > > process, then the parent returns and the child calls > casper_main_loop(). > > > The child and the parent both have a socket to communicate. > > > casper_main_loop() calls zygote_init() and that one blocks on fork(). > I do > > > not know how it could be. How can fork() block? > > > > Does you module somehow use pthread_atfork()? > > > > > The parent process later calls cap_service_open() and that function > calls > > > cap_xfer_nvlist(). Because the child process is stuck somewhere in > > > zygote_init() it never sends an nvlist back. So ping blocks. > > > > Can you show output from "procstat -kk " when this hang occurs? > > > > > All this is figured out by inserting printf()'s. LLDB refuses to run > ping > > > with 'error: Child exec failed'. > > > > Presumably it needs to be run as root since ping(8) is a setuid > > executable. > > > > > =D0=B2=D1=82, 5 =D1=8F=D0=BD=D0=B2. 2021 =D0=B3. =D0=B2 17:43, Mark J= ohnston : > > > > > > > On Tue, Jan 05, 2021 at 10:02:37AM +0300, Vasily Postnicov wrote: > > > > > Hello. I wrote a simple daemon called ZeroDNS which provides > > > > functionality > > > > > similar to multicast DNS, namely it discovers other participating > > > > machines > > > > > over the LAN and stores their hostname and IPv4 address pairs. > > > > > > > > > > Here is a NSS module which allows the system to use information > from that > > > > > daemon: > > > > > https://github.com/shamazmazum/nss-zero-dns > > > > > > > > > > You need to modify /etc/nsswitch.conf, changing the line 'hosts: > files > > > > dns' > > > > > to 'hosts: files dns zerodns'. > > > > > > > > > > It all works on FreeBSD 12.2-RELEASE, but sometimes not on > 13.0-CURRENT. > > > > > For example, ping(8) just blocks when trying to ping a host whose > name is > > > > > resolvable with ZeroDNS. Turns out that programs built with caspe= r > > > > support > > > > > (like ping(8) and some others) stop working with my NSS module > (they just > > > > > block trying to resolve the name). > > > > > > > > Presumably it's the casper process (i.e., cap_dns) that uses your > > > > module? If the main ping process is blocked trying to resolve a > name, > > > > it's waiting for the cap_dns process - where exactly is it getting > > > > stuck? > > > > > > > > > Is there some kind of manual on how to write casper-compatible NS= S > > > > modules? > > > > >