Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1624459pxb; Mon, 8 Mar 2021 02:12:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDqgKOho9Ny5iAhnsiXwbdxm/5r95HGNa4A4jKy/V9ldmiMksTkiKUFky9+Mllp/1uReal X-Received: by 2002:a05:6402:1a3c:: with SMTP id be28mr21439400edb.125.1615198320320; Mon, 08 Mar 2021 02:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615198320; cv=none; d=google.com; s=arc-20160816; b=XXSOAPdU19/lioVKJg4wGAFvTDBbcGNt2I9o5ldEoAc95xvkC2aYpSx4lT65JHnyss KBiUsux9UwI5HZbf9zZ/gxnv6ElWnXCnaQzKDm4JZ+U8Ax39Cyx5aE4WI5q9qk5bzBH9 AFli9Mc4WUYgTVjDEMNiU+3nn1l/7UXTT/9jvwQayURzI8pBtD3XmQu5h0loXtnvjamJ x77s7kqrNuud/vxVHnYGUSLw2ib62a37WonQ6LkxjABW5VYMnVxjY8JzNH6ciCJU5rCa gqgKAEFQMjerazOLzYODJyM+PsZltX5ZFTgLJ7SvobfMxul/6MTiTod+U6ADCfwdCj5b vEUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GbQjv9Mv0xwkm4S3YZaXGvRrT1lLub9Kj3fgmokzjW4=; b=N+MPQSj0jxs2jboB2aRj/tzb01kDf38xm0nNRzu9BmtkPULBRxiGh+k3vwETQQTnW3 VQ7Ko8bgU0/JYQJodNie5lVT/35sPTjxz4ga2XZar0SvRFVKbR+CXM2HxU5Piglme747 /s1IPFcmPznlZw7u724h0QsSwZ1aDxiVHC0zHKdldlptrNz0K8wPw/B4+bLtgmAS3D1V cAVOwSCKgfoiNOk3aMj/8A5wLxfXU7pMSr6yuhtmJoYVLvYNaDUr8o8tT791C3X12+Rw Ers1YVnB39ngV58uXPu1alR5LWXlUUSj/qlXK8qd/i1+Hb0GOC0GiNEVZ/NmjgARxyD5 6b/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a0oAH8gS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si7136412edj.431.2021.03.08.02.11.38; Mon, 08 Mar 2021 02:12:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a0oAH8gS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231439AbhCGSgb (ORCPT + 99 others); Sun, 7 Mar 2021 13:36:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbhCGSgL (ORCPT ); Sun, 7 Mar 2021 13:36:11 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA011C06174A; Sun, 7 Mar 2021 10:36:10 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id v14so6859825ilj.11; Sun, 07 Mar 2021 10:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GbQjv9Mv0xwkm4S3YZaXGvRrT1lLub9Kj3fgmokzjW4=; b=a0oAH8gSJAuVdMBJWrQAPcBJBnIpFsqf5RdWDv74K0aeGDFR1fPviY5JkGjDGpIwmV X+nSeicvJXEJcqO1GqQY81FhFlKc2iOio11xz7e9EgLLmXD2OER8shUyvzOIHPAKsx4T JhKlaGcRk/lndKMUgdsjHQMPYhDk1VuqC64paodEMIaFosHTsVdg0VCMsG3Weh1c+6iv wSJbXaa+wlYasUw/PkmMNN4GbpR2MbcFP2oV3U45DFqbNy4uEOD0HlFk2w6Eo8cl24va tS94lRcoAPM7/XdPwlE2BcDFdjDoe8PFezRY1EaOIA0K+JXw3YIJ5+GFfEkX4SHBfK7T JHbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GbQjv9Mv0xwkm4S3YZaXGvRrT1lLub9Kj3fgmokzjW4=; b=EpLbx94UndqZQmxqSn1gDG62ddzgJTKwZh5XOQwIvnFVZSDqVW4qzp1bTbLxvAoRmc DwuAAtZdmTPu+Dcq0a97cv7BPmvRH9v+oowYnOyhiPVNIUiGogzOKFNIEIF/BknIgb8p VGmJp/YEurUVy1czLzLNnzp73d6hinvbhqBM4hl/qOCBx8Qb0esBeQsK+TnSBZKXRTx0 rAAQOmXLPS9e92rZTijwmqyIlxXDWyLUrsIxrsPEe9iyXf0BYzFgFBkhGytveX4ePHT5 CsvXhCSwJWAdG5OaV8n2UE6nDG0bqYog+/ono0CmdOLcj0pFc8i7k8EvlTfBiVJF6+fo xWgQ== X-Gm-Message-State: AOAM5316ajm8cJtK/YLTS2kUcUUURwzmFIZ+z62jIVxn4ZGHDxYQOWDa pNVdlPTjNJ0Tg4eBssZ4Xqg1fXnfEOJHZGZWOcs= X-Received: by 2002:a92:194c:: with SMTP id e12mr17228526ilm.292.1615142170260; Sun, 07 Mar 2021 10:36:10 -0800 (PST) MIME-Version: 1.0 References: <20210306164710.9944-1-ardeleanalex@gmail.com> <20210307123658.3bdc0016@archlinux> In-Reply-To: From: Alexandru Ardelean Date: Sun, 7 Mar 2021 20:35:58 +0200 Message-ID: Subject: Re: [PATCH] iio: buffer: fix use-after-free for attached_buffers array To: Lars-Peter Clausen Cc: Jonathan Cameron , linux-iio , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 7, 2021 at 2:54 PM Lars-Peter Clausen wrote: > > On 3/7/21 1:36 PM, Jonathan Cameron wrote: > > On Sat, 6 Mar 2021 18:47:10 +0200 > > Alexandru Ardelean wrote: > > > >> Thanks to Lars for finding this. > >> The free of the 'attached_buffers' array should be done as late as > >> possible. This change moves it to iio_buffers_put(), which looks like > >> the best place for it, since it takes place right before the IIO device > >> data is free'd. > > It feels a bit wrong to do direct freeing of stuff in a _put() call > > given that kind of implies nothing will happen without some reference > > count dropping to 0. We could think about renaming the function to > > something like > > > > iio_buffers_put_and_free_array() but is a bit long winded. > > > > Otherwise, I'm fine with this but want to let it sit on list a tiny bit > > longer before I take it as it's not totally trivial unlike the previous > > one. > > Maybe to go with naming schema of iio_device_attach_buffer() call this > function iio_device_detach_buffers(). We grab the reference in attach, > and drop it in detach. That actually sounds like it fits beautifully ( the iio_device_detach_buffers() name ). Thanks for the hint. I'll send a V2. I didn't consider more on the renaming of iio_buffers_put() because I was a bit stressed by the silliness of the use-after-free bug. Thanks Alex > > - Lars >