From patchwork Sun Jun 13 09:01:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Adair X-Patchwork-Id: 1491384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kQbBIhQ4; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2pY056qTz9sVb for ; Sun, 13 Jun 2021 19:04:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type:List-Help: Reply-To:List-Archive:List-Unsubscribe:List-Subscribe:From:List-Post:List-Id: Message-ID:MIME-Version:References:In-Reply-To:Date:To:Subject:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7gd2DVnnRwucpjHpYQbpFUyK+OKYr1N11SV4VEYAQq0=; b=kQbBIhQ4U6DnaFh8gaX7wxRZ8R UDdrWqyqO+7G/pprtCvNTMagYN0udp0Z3fy25l0t6xmFEoW8hKbs/48kiwR1wF12qXLo6nblP95jo br6VBJRyTjO3lNbAEd3/iAnWTApaDLoo6DUD0xrcj3eINIEWehQTx7DEKTFnUEZpNrJ6zAOUDabhz 9DGNS1PO9xkDCivtJw7ziyUwCp/qReN2AtBXT1hooZsVXUI+keNKxHxND86w2bx2Cm5LULJ1aDQNp fnwmCmDDurHZ7fFx0kEpkYWB09qBBG257iWaOcPrW7XWaZEwKY6tfSP9gD1/VTh+/t8W7LZDOkvFl sAtPgYRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsLzW-00A2VR-SN; Sun, 13 Jun 2021 09:01:14 +0000 Subject: [PATCH v2] fstools: blockd Check /tmp/run/blockd for existing mounts To: openwrt-devel@lists.openwrt.org Date: Sun, 13 Jun 2021 02:01:04 -0700 In-Reply-To: <66fdd10bfbece0f31a1cf40d2159a9db97c4da56.camel@aol.com> References: <0e043bf93515992fdd95ee33300b4eb4a1d6da9e.camel.ref@aol.com> MIME-Version: 1.0 Message-ID: List-Id: OpenWrt Development List List-Post: X-Patchwork-Original-From: David Adair via openwrt-devel From: David Adair Precedence: list X-Mailman-Version: 2.1.34 X-BeenThere: openwrt-devel@lists.openwrt.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: David Adair List-Help: Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The sender domain has a DMARC Reject/Quarantine policy which disallows sending mailing list messages using the original "From" header. To mitigate this problem, the original message has been wrapped automatically by the mailing list software. Currently volume names can not match rootfs files/directories so LV names like "home" "usr" or "www" are not allowed. This changes the check for existing mount points to examine /tmp/run/blockd/ instead of /. It also checks that a link is present at /mnt/ and skips the request if it is missing e.g. the "map" does not support the requested "key". This aligns the mount logic to match the automount daemon indirect.c logic from kernel.org. - If mountpoint exist and is not a zombie return success. - If mountpoint is a zombie delete it. - If map is missing or mount fails return failure. This greatly simplifies hotplug-remove since we leave devices alone once link is removed. It also fixes most instances of poision directories remaining in automount dir and causing "too many symlinks" errors. Signed-off-by: David Adair --- blockd.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/blockd.c b/blockd.c index d6dfeb8..6024c60 100644 --- a/blockd.c +++ b/blockd.c @@ -41,6 +41,7 @@ struct device { static struct uloop_fd fd_autofs_read; static int fd_autofs_write = 0; +static struct stat autofs_mp_stat; static struct ubus_auto_conn conn; struct blob_buf bb = { 0 }; @@ -501,8 +502,10 @@ static void autofs_read_handler(struct uloop_fd *u, unsigned int events) { union autofs_v5_packet_union pktu; const struct autofs_v5_packet *pkt; - int cmd = AUTOFS_IOC_READY; struct stat st; + struct device *device; + char *mnt; + int cmd = AUTOFS_IOC_READY; while (read(u->fd, &pktu, sizeof(pktu)) == -1) { if (errno != EINTR) @@ -517,9 +520,24 @@ static void autofs_read_handler(struct uloop_fd *u, unsigned int events) pkt = &pktu.missing_indirect; ULOG_ERR("kernel is requesting a mount -> %s\n", pkt->name); - if (lstat(pkt->name, &st) == -1) - if (block("autofs", "add", (char *)pkt->name)) + /* + * if MP exists send "ready" + * second part of check detects zombie mounts -- + * valid target should have target dev not autofs. + */ + if (asprintf(&mnt, "%s%s", AUTOFS_MOUNT_PATH, pkt->name) == -1) + exit(ENOMEM); + if ((lstat(mnt, &st) == -1) || + (S_ISDIR(st.st_mode) && st.st_dev == autofs_mp_stat.st_dev)) { + rmdir(mnt); + device = vlist_find(&devices, pkt->name, device, node); + /* Map doesn't exist or mount fails send "fail" */ + if (!device || !device->target || + lstat(device->target, &st) || ! S_ISLNK(st.st_mode) || + block("autofs", "add", (char *)pkt->name)) cmd = AUTOFS_IOC_FAIL; + } + free(mnt); if (ioctl(fd_autofs_write, cmd, pkt->wait_queue_token) < 0) ULOG_ERR("failed to report back to kernel\n"); @@ -562,6 +580,7 @@ static int autofs_mount(void) return -1; } close(pipefd[1]); + stat(AUTOFS_MOUNT_PATH, &autofs_mp_stat); fd_autofs_read.fd = pipefd[0]; fd_autofs_read.cb = autofs_read_handler; uloop_fd_add(&fd_autofs_read, ULOOP_READ);