From patchwork Wed Jul 3 19:28:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 1956418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=NhdJgzVE; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=AzRzJKkx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::238; helo=mail-oi1-x238.google.com; envelope-from=swupdate+bncbcl4hcw73qcbb66ms22amgqet7oln4q@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-oi1-x238.google.com (mail-oi1-x238.google.com [IPv6:2607:f8b0:4864:20::238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WDqb3420Yz1xqb for ; Thu, 4 Jul 2024 05:29:02 +1000 (AEST) Received: by mail-oi1-x238.google.com with SMTP id 5614622812f47-3d5608530absf5113558b6e.0 for ; Wed, 03 Jul 2024 12:29:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720034940; cv=pass; d=google.com; s=arc-20160816; b=rdd5F5eyaWXWs6Lwb523YRHF3SjWEnS4fTY57xsaqXYl6JNjF2tRItMdI1iZKA4mvU FC7TG4CHuVPfcpB+UGiIdQ9NsRV2Jt+BcUgxOM/DdgGttIE51wx9DyzTD3aZ3BZ3DXgn j4qU7K6FWwk+kCCpVT1ITjYYo3jlhkILXVNNx+uuwdkOqq+TVflRx+BtcJZkUwAZwbQJ tnSE+i98FmTn8aodwNyw6iCtE6PjLtOVAvKzBWpvx66qw6zjrlMbwlx5zYtpO3ZweObC RPzJCq2eKCoGtueDCwdn/vwuM25lSnJr7JF6AH/DyjQzkAYe8/VOmPihkv0iU4ywveuG BgNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature:dkim-signature; bh=uL9AV7egI112dCb0uTZoVHHtB6l+Qzj7VZoLRXTHBlA=; fh=clxBJ9WbbV+uifuvtaFg9HHjvvHU1K2JWOt8kh9GGlc=; b=DVC6GT0KeOY93gUHyMGOKc0ZA7rtl1cF8ZItAmzaQm7dan77Pqxott/z6npMCL/BJn fxAudqlWrsk4TPm2wegHVJAcgJLzDnRHkSYJO5K4vFj1vBK7wVhThmJBfq4ulPzStt7Z K5Wmj2esNLQTLLLIIFAECYXk8mAKp1m8z74fXlsPlOnAMGuY2gQulgIvrTFvkI29pgWe TQNWj4F3zqDk43y6pDM3qcREiqUGk54LF9S/lrQkHuR9+N0oGRZJmfv7T89C44n+Yjh4 cliAiQz5Bo/m4/yAnrrSNrSpg/6kDXNChL+hafK0XmnLfxixf4sV7t43dg0TwmdX9fkk 2Ldw==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WoYLzbYa; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d31 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1720034940; x=1720639740; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=uL9AV7egI112dCb0uTZoVHHtB6l+Qzj7VZoLRXTHBlA=; b=NhdJgzVE1J78XGCuEiHGA99FRS8LVAsVjK4Tqovu/DlcR12eyzH7fjJTgsH19711Xh FFEc5L1RqFKA7n8EGb6WKNBpm4FTJKyrmkPs35y8EOm0SZbWA5ZeKT7rT6t5NRtCARMd OjqaXtW+K79xm9QMbeijme7A8X161Dl32MfjeEtEC9E3vzJclDp/12J0iCNsmTsZF1QI itN21AdInAyY+pn6R7vYpzFRbQUB84PiaM31A/G2KNXMCJ+X4Fke4ok08H37vOtVsW+v S7LSccxkVdXBmULs4OHahRJ8tpDi/KzplyqGe2axMkI/g3zDuPX0XNPl+lOv5lo/XbId jDzw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720034940; x=1720639740; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=uL9AV7egI112dCb0uTZoVHHtB6l+Qzj7VZoLRXTHBlA=; b=AzRzJKkxyB2BX9+4z6JllsiHlD2WCFtJdk/cT95a5jFz/s4HTzXSZaN/EzyT4rOITz g4tPvrmoglYDBxnVICWd5vvJBVJgBpG+tRXPojULWD0Sd0Un5FTB1CctmYDhzqLQTxwY iV1CkSO1lq2UqdWXSOd20kXpiDaInDExCdKoSJN/xAxJHSgfOuCcL3cgQeiF9DfocXgD ZbIRbub7JiFLgjwomhB1YO2vJ1wMzgbKjytXKhwry0eA6/C2SRfO8zl6aKHRyB6bL1GZ C3fAqRKHnMEIMSYevJ+dT6E+wPqW+PBaU/kziZerFHk0mm1jGB7Bio043ORFsYG68Nf1 9fwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720034940; x=1720639740; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=uL9AV7egI112dCb0uTZoVHHtB6l+Qzj7VZoLRXTHBlA=; b=EXmSR574R08Kr2t/sXjZnNS5PwbKAOspv4ubHjoB3Stv7/C5MJ9ihndHuQrG0mRC1n cufTnV8jZza+m88hZhKb/W89GwSXi/7aqBpHVbH68MgkB8E4oe1gLgHGmTUwlra47jGL 2uXa8cbzR5r9mapdVpTU8MaAYQsyHZ01xWSvkUm2JBwuweMyVnYc87xswrgvHtuZDHR0 vht+upvROfYQnNwipKGGoDYG+7dhPBfmPa/wALHxO3OfMCF8qhKH7VBvxC141P7iCxUc ilifNvIBnP8nYcPqtu1KVQbjSCXBakis2OL7XxSkE+eZzeR91rY+ylJDShx5xbtiS71n AcDg== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCXHfTRtXQBnMq3DTzEPZ+zedhS8+Gf451rCGMfJppwT6ncmGctEj/Ntdv1+BwYd2Yq4ns/tnfrcFOJQ/RqrEDJpBtpub/6WXVO9K77G8w== X-Gm-Message-State: AOJu0YxTtvg3TehlgWQwQ+9pC8Nb8PMx+Yp77Gfni3xyBCGgNpK0MDtk XPR2/L9JOaXUuECr+LZWXGfk4FAAe2RHpcbFn2fTyfx4sHA3LFgG X-Google-Smtp-Source: AGHT+IHLp+IWPX4LReDQybLkDKk1v8BJj0oJyT/5SvJWefAsA9TNlpQgTHCq2U5fhdNz+s/8x4o/Vw== X-Received: by 2002:a05:6808:15a8:b0:3d6:2bb8:82ab with SMTP id 5614622812f47-3d6b4de1fc9mr15798973b6e.36.1720034939602; Wed, 03 Jul 2024 12:28:59 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6214:ac5:b0:6b4:ff5f:6a65 with SMTP id 6a1803df08f44-6b5ea37d98dls277166d6.2.-pod-prod-05-us; Wed, 03 Jul 2024 12:28:58 -0700 (PDT) X-Received: by 2002:a05:6122:4f90:b0:4ed:185:258c with SMTP id 71dfb90a1353d-4f2a563e12bmr16817326e0c.2.1720034938172; Wed, 03 Jul 2024 12:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720034938; cv=none; d=google.com; s=arc-20160816; b=rYkpQpq8W7QFFlvH7J7FZhyCz09Qr70/sjcRjvxt+7Koksyigf3zGbp6eSzA1ubXa4 Du/P+/y+JzGCNI49uu5qL9Ozi+BoVJTG2bgDQJKfeHBObUdONU7YCh9wU5rBUUhJBnGO m+UlIJB+DezwXAks4l94jz7pSEiGBGjp0eiLO1tbvqWxQZYGP8Yg+/fD15JwZ1jm8z+Y a1Am0KsUnN9WpLptXExSapJQdRE7AabkO+oiLTy4nsNNlfejzgzLh5zunI+LZw28LUWe oRMoJnQ+8z1WvprpgQyxq9gbcqSxclF+QyGRg55FhKGgt1lfgLjpSenlRGdtMxuvpTXp fqIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=fyuUNLt2jdx1cu/slRfcB+NLPzzRUnw9dgb22sNrkUU=; fh=KPrAw848PoyEggiIX82ubXk7sJG2UD396EeWf1FQVUo=; b=gvYfOkNlQqp4hgS6TpqENZQeXzQph0wX6nH4oxcMBUWV6V+YfMLj2wrDwU6Y0Yq5WJ 0P0+aFnzN/mHxPFOUhbjfFK4DIb7WaGD/o/4c92+QMKcQ/ltBnACDmOYh+hu5d5jodMK AZHY1+hyR1XdyrVuV5IaTTpsgfAu7alZhl/JEmPTxt1mgMUcJfUwgstdHaQKXRgzrJ06 mhUizCuo9fuAtEFGuf0GnHjypY32LG/sJu0x70uqDW6qnHr4l8Mb8eQ9bpO5/0XqJIsw Zjj1iTUsd2Hs+XcGly2T0QC9VQRytgFtnZHLvDk1imjDUtokGC4oSkecJ17Tdwj2H8ih bZug==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WoYLzbYa; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d31 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com. [2607:f8b0:4864:20::d31]) by gmr-mx.google.com with ESMTPS id 71dfb90a1353d-4f291cfb76csi754756e0c.1.2024.07.03.12.28.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jul 2024 12:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d31 as permitted sender) client-ip=2607:f8b0:4864:20::d31; Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7f63db7a69cso194734239f.2 for ; Wed, 03 Jul 2024 12:28:58 -0700 (PDT) X-Received: by 2002:a6b:cf18:0:b0:7eb:7f2e:5b41 with SMTP id ca18e2360f4ac-7f62ee196dcmr1448774339f.9.1720034937259; Wed, 03 Jul 2024 12:28:57 -0700 (PDT) Received: from james-x399.localdomain (97-118-179-167.hlrn.qwest.net. [97.118.179.167]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4bb9b4b1d3esm3099508173.169.2024.07.03.12.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 12:28:56 -0700 (PDT) From: James Hilliard To: swupdate@googlegroups.com Cc: James Hilliard Subject: [swupdate] [PATCH v2] util: Ensure swupdate_remove_directory unmounts path Date: Wed, 3 Jul 2024 13:28:54 -0600 Message-Id: <20240703192854.1026436-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: james.hilliard1@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WoYLzbYa; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d31 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , In the event that the DATADST_DIR is left mounted we should ensure that it is unmounted prior to deletion, otherwise we may end up being unable to remove DATADST_DIR and/or accidentially deleting files inside the mounted filesystem. Signed-off-by: James Hilliard --- Changes v1 -> v2: - fix stat return value check --- core/util.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/util.c b/core/util.c index 70f0d28f..33a9af71 100644 --- a/core/util.c +++ b/core/util.c @@ -169,6 +169,26 @@ void swupdate_create_directory(const char* path) { } #ifndef CONFIG_NOCLEANUP +static int _is_mount_point(const char *path, const char *parent_path) { + struct stat path_stat, parent_stat; + + if (stat(path, &path_stat)) { + ERROR("stat for path %s failed: %s", path, strerror(errno)); + return -errno; + } + + if (stat(parent_path, &parent_stat)) { + ERROR("stat for parent path %s failed: %s", parent_path, strerror(errno)); + return -errno; + } + + if (path_stat.st_dev != parent_stat.st_dev) { + return 1; + } + + return 0; +} + static int _remove_directory_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { @@ -187,7 +207,23 @@ int swupdate_remove_directory(const char* path) ERROR("OOM: Directory %s not removed", path); return -ENOMEM; } + + ret = _is_mount_point(dpath, get_tmpdir()); + if (ret < 0) + goto out; + + if (ret) { + WARN("Unexpected mountpoint, unmounting: %s", dpath); + ret = swupdate_umount(dpath); + if (ret && errno != EINVAL) { + ret = -errno; + ERROR("Can't unmount path %s: %s", dpath, strerror(errno)); + goto out; + } + } + ret = nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS); +out: free(dpath); return ret; }