From patchwork Tue Jun 8 03:09:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Adair X-Patchwork-Id: 1489080 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=KJ0fNC2p; 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 4FzZxx0qGYz9sW8 for ; Tue, 8 Jun 2021 13:11:01 +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=bLJGvcLzdzxvl7bIUtScqM33TKw8KIy2m6jWf14WmzU=; b=KJ0fNC2pzLhSsSWz8H6yadZxsa Lz5IFBNiBdG11eIU0Y/kpzR6SM0rN4MOo08qx9PwNsExWFdI5synIg9/THmFrqRMAPeA3trJDQgAV USjvv3VoqaH5F9Bt/cRWquY2ieMkFnic0TvQJKTu1S8BjeMEt4hvqZpLRabnGYVqYxDAgdYr3MyRY MnQhn4kx/Sfl9ZIzGKRTcBkC1zYR07CfwsRl0YBU9gdE9SSx2Btehcw9sbJ+DN1FanLWAqBWA0FCx hG/j+4ICd+SbQVPom0CN8Iv8Gd3S29U5F/9UXMUBHSjhym8m5EufM/8YLP3sEyCE7GSm9ymSbALui eRozFkJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqS76-006C91-OU; Tue, 08 Jun 2021 03:09:12 +0000 Subject: [PATCH] fstools: blockd Check /tmp/run/blockd for existing mounts To: openwrt-devel@lists.openwrt.org Date: Mon, 07 Jun 2021 20:09:02 -0700 In-Reply-To: References: 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 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 | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) if (errno != EINTR) @@ -517,9 +519,23 @@ 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)) - cmd = AUTOFS_IOC_FAIL; + /* + * if MP exists send "ready" + * second part of check detects zombie mounts -- + * valid target should have target dev. + */ + 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); + sprintf(mnt, "/mnt/%s", pkt->name); + /* Map doesn't exist or mount fails send "fail" */ + if (lstat(mnt, &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 +578,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); diff --git a/blockd.c b/blockd.c index d6dfeb8..eacea27 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 }; @@ -503,6 +504,7 @@ static void autofs_read_handler(struct uloop_fd *u, unsigned int events) const struct autofs_v5_packet *pkt; int cmd = AUTOFS_IOC_READY; struct stat st; + char *mnt; while (read(u->fd, &pktu, sizeof(pktu)) == -1) {