From patchwork Tue Jan 5 18:34:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wes Lindauer X-Patchwork-Id: 1422678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::b37; helo=mail-yb1-xb37.google.com; envelope-from=swupdate+bncbdryvpejsaobblhc2l7qkgqezmgdasy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=NZZc/MiZ; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=e89EC6C2; dkim-atps=neutral Received: from mail-yb1-xb37.google.com (mail-yb1-xb37.google.com [IPv6:2607:f8b0:4864:20::b37]) (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 4D9LkR4dqZz9sVs for ; Wed, 6 Jan 2021 05:34:23 +1100 (AEDT) Received: by mail-yb1-xb37.google.com with SMTP id x64sf524158yba.23 for ; Tue, 05 Jan 2021 10:34:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1609871660; cv=pass; d=google.com; s=arc-20160816; b=k+w+hfi6zj3xO6lsoto7DApR7slXSuRz1NzUUjMnhShDvStkLPWRF3ng08wkyHbvD4 vyGOlY8dQE1geFCnVLbgL+wz8AU5Cae6MlP9fAkTzkTyhZOIHT6vDj8robeycJ4QvsEg KcERK+7x3wMv/qy9xwLGll1LKUzkcs1X85czgZ8epqrSqsoxtG+/+A7Qouj2YHkMhhZ9 9z0L0vAa77N7q0agDDKknEOyzYT6vOWpT6gVrnPrmCaPf0hc0dy2E8+lj9Bb3+9GgnJx Skn5DQ6grECV+X8NJvIMfYpymBOEQ+Tf+Ushdt9QGHT2SrptVY5RYX69OJJgK9U44dBM Pi0Q== 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:message-id:date:subject:cc:to:from :mime-version:sender:dkim-signature:dkim-signature; bh=Pzf2HJgxczcZkmBVzaOY7CAI1C8pQU+ZhvPWyXq3jhk=; b=EEfBnL3JkWrWcB9eyG+1RDXW2X8/2sbut53VYdsUWCu0YPZienU49rljdypKtvWTvv W40YBucKFq84D/YBREklKltJb8x3ZI8WLN1zXKf17utK0phJqf5PWzLqOqRUnlLciN4/ BIPYFVGBmJaWsZxKEwbbb0z55cfy1B3n7YnrCaiJhGVE9uXbRMMmbL0wqJi2A0wKctiu F4LY4bCy7xCsfs6FyClmBpbK6YcF/pi8n53UYpWJR8XAw6Din1A4Sah+4q+YNcjAydHs d3wjgGYntohKegrCjvS0vkDREam7vVI9CpcHxpxUKHBxCpRv8w4safPjQMqUQ1TZvAti SGcw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tx4Mnr2n; spf=pass (google.com: domain of wesley.lindauer@gmail.com designates 2607:f8b0:4864:20::f29 as permitted sender) smtp.mailfrom=wesley.lindauer@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=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Pzf2HJgxczcZkmBVzaOY7CAI1C8pQU+ZhvPWyXq3jhk=; b=NZZc/MiZBSURz/S21u5adXWzjuWu/OuVHDGPpJrftgjXkKW7KpPrESPe5m6X61oxR2 lVeoXQ1ulCT++SeS118mpX2ePdwTv/hAQra6ytwi8uQx4u2D7t26O5GMooACjn38y9vv bU++XFnbwOo345Xp5flepzpzebshSzeS3gOl4ccuqL8wMDGBkN1Xuk2GfPANTEunjJD9 5PnhRhX7Za8ggWg3L9HgrUEPs45o4CX0ZfaQPX5w3hdx+9tiwOJcIXZBDjy8yhGbTN8m +f6Q6QkAQ7+mFRtyAel43v8wQpx7YaIB679t+VHrufG+rd4IeGk6ozAEWzO97s+tV7WU vKHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=Pzf2HJgxczcZkmBVzaOY7CAI1C8pQU+ZhvPWyXq3jhk=; b=e89EC6C2H05Lynecqr/HWVK/TpruZMbBHMezWpU1QJQDTk9Fv6c25Eu1ZCZ9WVf4gM qk41Liis/+ZyHBTbkVrNu3ofelwCu+gq+bgRrSV408De0rmCaBhWwqe6M8TMA7WmtImz 5VzcM83ZUBmCdhn+kwcJJAVXOYu1V0o/B9t8ZiCicW+F/pPh9htHxHE3X2ARxTy3i2da WNZA4IePK1qHvl0avPTLdLIeYJYOZPswixP+7MIteWWF/bLlDqIAr0gU+GWjmYydwwlU n0WnPJv2hRLKTpelVBPKIKNLjy1EM1kxtIH5n+Jwrtea2IeXb4ywoWcGIQfz6yN4qVFr Zpmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=Pzf2HJgxczcZkmBVzaOY7CAI1C8pQU+ZhvPWyXq3jhk=; b=tU2gXHTIU1Oj8IcLj/NqeSILhwozKRqLg1JU8anRTHyHdfcQSup+FODfTVOdBGNPdq NgAxiEtb0bSHWcbDjCUFlIT+R0fBZKvLjdo4MNCxXHBZ7zik6B3gHfcHUg+/JI8RsB47 G6Sw9SzHAHRh8WV1FgdjVnsuo1jr7zyl84Ke0MW621whFmX2poZiMHywe6ySN+Zvl73x Ns+gww51RkUig9PVHicytAmbUEXvYIm6kfTNlg2Hcpk2BPiE3lqx4K3eMMCCV0M8MY+l EBqpo0DM8LG7OguTJPlQRXS0YH71L5OMjtelpBK17TZM1jxgTxKsDdPt/6vppBMJm7NZ v7vQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531BADizTaxLCWjmXipiYgS77EoSmBSzBka4qx5+mh6nmwCdKV1h kO8Kzbe42wf/yl7139qEbxE= X-Google-Smtp-Source: ABdhPJyXwh+pYXGhjEPhf9rdeQox9y3Mn0g/euNoqzXdtaLi1k2PlcPVADFlagUy3tUm/iTbrqtPJg== X-Received: by 2002:a25:1004:: with SMTP id 4mr1039040ybq.137.1609871660578; Tue, 05 Jan 2021 10:34:20 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6902:6af:: with SMTP id j15ls322339ybt.3.gmail; Tue, 05 Jan 2021 10:34:19 -0800 (PST) X-Received: by 2002:a25:1e86:: with SMTP id e128mr1079269ybe.326.1609871659756; Tue, 05 Jan 2021 10:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609871659; cv=none; d=google.com; s=arc-20160816; b=hS8PYrUk6GkERhfXUigxBDgAIWP6Y9fAYE6t76cf+/KvPJEaALbyeFlbP/rsOmIV4L DeGyP5GwODQK7vZw1itQUx4Jbkxr593bvn6nzOY2xfUB0Y+vB/c0btP8dz8d5Ijspbaj TaJIRG+458kWRc/BITwIcLLLWZQRNG1cxVz7c/ya/MP81+Tb4VDykAUg7Xaf3uP3cWCA QeutRr4aCVlnRJnlRBnuKg3CRR0+/7UizbTvf2Y5LNJt/iV7FvOD1zA/SCnB90yGI0DE WEa5JPU8jdJ49zw7ieed3GnQkR0nEBC56RHlW3FCRrhXaipocgH5pG1TaiaZjs73siM8 JLyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=BfHT3e/4ouYgts9A5kcvx9dtoTsp7FPlkmxppIuStDY=; b=eHh0TWcpwHFyOVXwJ4EbaGxuQjH06XapwXG2uMVqa0eelCx7rqhbSuTP8mfgF9biIM P8bPKbJNHWSQEeyqOUCasxAXFEXNrEWsOH1aGlq0ILD6skilvYkrDjWJybJIe+2lVvJA AdfDVocUUMiL/a24wEMYUxnvwShZhrtMMj7VS+fFk1HuxZjdwJnydwYDBr0K5Je0i/ex o0tq4/5w6PlCz7Z7awpFohZoPScgr60ongQL7asLk960v61d64zhSe/smcR0SMA6zc90 GC0SvKxX1MXKujUTLrC9Bw4NFjlQh+c8Kwfnpg4QvhN9gN3ln+nn0Sb0qSUraRd6BNpP F0RQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tx4Mnr2n; spf=pass (google.com: domain of wesley.lindauer@gmail.com designates 2607:f8b0:4864:20::f29 as permitted sender) smtp.mailfrom=wesley.lindauer@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com. [2607:f8b0:4864:20::f29]) by gmr-mx.google.com with ESMTPS id i70si5476ybg.1.2021.01.05.10.34.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Jan 2021 10:34:19 -0800 (PST) Received-SPF: pass (google.com: domain of wesley.lindauer@gmail.com designates 2607:f8b0:4864:20::f29 as permitted sender) client-ip=2607:f8b0:4864:20::f29; Received: by mail-qv1-xf29.google.com with SMTP id az16so102607qvb.5 for ; Tue, 05 Jan 2021 10:34:19 -0800 (PST) X-Received: by 2002:a0c:a789:: with SMTP id v9mr823866qva.41.1609871659334; Tue, 05 Jan 2021 10:34:19 -0800 (PST) Received: from nova.caas.local (cpe-65-24-166-29.columbus.res.rr.com. [65.24.166.29]) by smtp.gmail.com with ESMTPSA id r10sm343396qtw.66.2021.01.05.10.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 10:34:19 -0800 (PST) From: wesley.lindauer@gmail.com To: swupdate@googlegroups.com Cc: Wes Lindauer Subject: [swupdate] [PATCH] raw handler: Allow symlink traversal in blkprotect Date: Tue, 5 Jan 2021 13:34:07 -0500 Message-Id: <20210105183407.25126-1-wesley.lindauer@gmail.com> X-Mailer: git-send-email 2.17.1 X-Original-Sender: wesley.lindauer@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tx4Mnr2n; spf=pass (google.com: domain of wesley.lindauer@gmail.com designates 2607:f8b0:4864:20::f29 as permitted sender) smtp.mailfrom=wesley.lindauer@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: , From: Wes Lindauer If the device given in the sw-description is a symlink, this will traverse the symlink to find if the underlying block device has a force_ro flag. This is useful when using device symlinks with udev rules. i.e. /dev/disk/by-label/boot -> /dev/mmcblk0boot0. These udev symlinks can be helpful when using an A/B partitioning layout. Signed-off-by: Wes Lindauer --- handlers/raw_handler.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c index 489919d..b14642e 100644 --- a/handlers/raw_handler.c +++ b/handlers/raw_handler.c @@ -38,6 +38,7 @@ void raw_copyimage_handler(void); */ static int blkprotect(struct img_type *img, bool on) { + char abs_path[PATH_MAX]; const char c_sys_path[] = "/sys/class/block/%s/force_ro"; const char c_unprot_char = '0'; const char c_prot_char = '1'; @@ -53,7 +54,7 @@ static int blkprotect(struct img_type *img, bool on) return ret; } - if (lstat(img->device, &sb) == -1) { + if (stat(img->device, &sb) == -1) { TRACE("stat for device %s failed: %s", img->device, strerror(errno)); return ret; } @@ -61,7 +62,13 @@ static int blkprotect(struct img_type *img, bool on) return ret; } - ret_int = asprintf(&sysfs_path, c_sys_path, img->device + 5); // remove "/dev/" from device path + // If given, traverse symlink and convert to absolute path + if (realpath(img->device, abs_path) == NULL) { + ret = -errno; + goto blkprotect_out; + } + + ret_int = asprintf(&sysfs_path, c_sys_path, abs_path + 5); // remove "/dev/" from device path if(ret_int < 0) { ret = -ENOMEM; goto blkprotect_out;