Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp268690ybv; Thu, 6 Feb 2020 22:40:18 -0800 (PST) X-Google-Smtp-Source: APXvYqy+7JtlTy+HeLfS8+vAbfLtFx1jnHhdqXKTmpJ4pS9Ap42P0v0zm+WGeFZsD9pxnPaT3crY X-Received: by 2002:aca:56ce:: with SMTP id k197mr1170440oib.99.1581057618104; Thu, 06 Feb 2020 22:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581057618; cv=none; d=google.com; s=arc-20160816; b=hAkInZV/DrQT+UY5E050pg06LRbN0ki+sL8nswFp06f74HnySrHh6YaPB1OxqcpQ2q 9aJgrrDh8eH2m67NOWdBTskwMNUw/2SqPl1pqkA6IZGkk4UnPiBlBf8NxgKl0TrIUkBN eUyZTuPmSzvW50lio7qJpYRw3gR7FaBFPLZrx0700u2cUAabOevGcAzrl2VNF0h2VM8j RY3CT8XqeYd5HP9ia3gugmbJEJW8l0f8qDsOFT9R93X9i3BdUYzsCg02dTM7XMFx2iPi QujQtqsiMVhrdc1cRungmRvMNPvohFt5KCbmF8e69PTdrwDTfNPbKBKzT6srDIOzwMGD /sXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kTP1QtOdOBfTVKKE4wNHeXKdsy4uhX84+GQlCDpFRcg=; b=bzLjTcy33kK0FcswjojnCD7LpFwjuTtobPmBVqOP0140It194/uClpUp+J8GVvbeye uocVtGDaWJ7Hdv+vV4l+uxvcCe658ytZbuYRd4u7d0HNW/QXK9yZNgWrYKk1cU3XEcZb EliXHyGWshH9IttoY8Fd46yLOTKuBUIf86w4Sf66VRln1bGZWiW2iHhGI1wsKU8HVZ24 7LWF5rqfUQ7fNlrWCFsi0emcTV5Ebh/leHE3eSDXIGaTMS4yDwaOTrFSmX9n6XTbjkgM cRF9rqubFGZhE3VWBcqBlyA6yMUtb/FnpXK71OTAfM3FWjGhfB2MykS05cqCBn+BQOi0 Jqmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13si1227972otq.30.2020.02.06.22.39.48; Thu, 06 Feb 2020 22:40:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgBGGjs (ORCPT + 99 others); Fri, 7 Feb 2020 01:39:48 -0500 Received: from mga02.intel.com ([134.134.136.20]:53801 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgBGGjr (ORCPT ); Fri, 7 Feb 2020 01:39:47 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 22:39:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,412,1574150400"; d="scan'208";a="264888587" Received: from ingas-nuc1.sea.intel.com ([10.254.98.3]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2020 22:39:46 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Fix keyring app keys directory iteration Date: Thu, 6 Feb 2020 22:39:45 -0800 Message-Id: <20200207063945.21943-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This fixes how app key files are accessed when finalizing Key Refresh procedure. Instead of using open(entry->d_name, ...) to get file descriptor, use openat(dir_fd, entry->d_name, ...) since entry->d_name contains a relative app key filename, not an absolute path. --- mesh/keyring.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mesh/keyring.c b/mesh/keyring.c index 41cb2e980..29c5f1e8e 100644 --- a/mesh/keyring.c +++ b/mesh/keyring.c @@ -123,12 +123,12 @@ bool keyring_put_app_key(struct mesh_node *node, uint16_t app_idx, return result; } -static void finalize(const char *fpath, uint16_t net_idx) +static void finalize(int dir_fd, const char *fname, uint16_t net_idx) { struct keyring_app_key key; int fd; - fd = open(fpath, O_RDWR); + fd = openat(dir_fd, fname, O_RDWR); if (fd < 0) return; @@ -137,7 +137,7 @@ static void finalize(const char *fpath, uint16_t net_idx) key.net_idx != net_idx) goto done; - l_debug("Finalize %s", fpath); + l_debug("Finalize %s", fname); memcpy(key.old_key, key.new_key, 16); lseek(fd, 0, SEEK_SET); @@ -153,6 +153,7 @@ bool keyring_finalize_app_keys(struct mesh_node *node, uint16_t net_idx) const char *node_path; char key_dir[PATH_MAX]; DIR *dir; + int dir_fd; struct dirent *entry; if (!node) @@ -170,10 +171,12 @@ bool keyring_finalize_app_keys(struct mesh_node *node, uint16_t net_idx) return false; } + dir_fd = dirfd(dir); + while ((entry = readdir(dir)) != NULL) { /* AppKeys are stored in regular files */ if (entry->d_type == DT_REG) - finalize(entry->d_name, net_idx); + finalize(dir_fd, entry->d_name, net_idx); } closedir(dir); -- 2.21.1