Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1301246ybt; Thu, 25 Jun 2020 02:46:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6lr5Mf4Tw+9YPsiTCKeSbcgK9QMEAIVPl29NeNi0X0nouKSH3L8tfmjZqs4AT5VXuAKsA X-Received: by 2002:a50:cfc4:: with SMTP id i4mr30509561edk.252.1593078403726; Thu, 25 Jun 2020 02:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593078403; cv=none; d=google.com; s=arc-20160816; b=in1RVV8lt7g6/jeyCXhzVRT+GnIvab7Uhq0TZFxWnQOHlpQ7A9FTxzFHfkLFM0uuIR VK/xaoK9CBVAhfuK/Qzdr9xDOBR3u9Skak6PZFp3veQA3wYDABIM2h7FI4CD1dRzM6hj POvnObVWkaGc2LGFt550vp4sbJkbSkltS9EymnpzM+sKWoiaPcUJlDKC4YN6MH9nVvEJ qyJtjqNDWdx+UeDtKXTFOghjU1nZQzYhtvugwraeBcZ2ZoQnAjVJVmIifDfSBeQ9Iwa3 FbKnehskcn4AUnUKhe+r0XsxZLtlrp63SYCMemmOKlWEmk5DqP7cxrNW9LiacJqjbi+Q bo4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=SPuyZpiaeMW7v65IWK0vJIfRpGGit+CNrEvkfOmMaMI=; b=v6IjKUb4N8y45WnFCYTY6LKLnSjFxqVjt5GsJWGd4yIRtxDYqJxByPwA8sF7fkcruA ksp/gWV+0K9xUm2LH0kLMOxQHyq2ClfjE6nakub0dvxOPDZ9voY+0n2bjpG6li5FEUh/ tzA1pXEEYKbJmKRh8HsVan6szFkWPydhm56R3uwIfsJfmJeHZ3lVFqs+JZIBnBYsTs0a X6532+sCYSFiw+We7bdqaLJYbRVG9xiQKL3mLJe0Nv0wtMRzfAAgV2BmYer5JdtaB4lY AqEAMe0lEZSWXCZrL76JWjvZ3y8Q6vGfe6Haglci2PFWVScP6yDAXSEqnvx+me/yqKee c7FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h0L6gU8J; 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 i9si17341199edn.437.2020.06.25.02.46.20; Thu, 25 Jun 2020 02:46:43 -0700 (PDT) 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=h0L6gU8J; 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 S2403784AbgFYIof (ORCPT + 99 others); Thu, 25 Jun 2020 04:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390025AbgFYIoe (ORCPT ); Thu, 25 Jun 2020 04:44:34 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86507C061573; Thu, 25 Jun 2020 01:44:34 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id t6so3004894pgq.1; Thu, 25 Jun 2020 01:44:34 -0700 (PDT) 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=SPuyZpiaeMW7v65IWK0vJIfRpGGit+CNrEvkfOmMaMI=; b=h0L6gU8JGT61YqfoP+6NtN2CGutWMoBlAPkHcd0b+WTQUkyP3+uZwq2EPf7xRZw1ik L3LTpgiJk3k87izqf3vzxiQLnqp+Gsa8Ls3SCDIyxJvUEHiPzbsbWgoyxpQEnwZdJ8Ef FP7BH16dCiXgYKUXAG3pfmrbrpgy6t5iAWXD+oebejGXRNROLQlzBQtT14XA8RwJP/0g kdMHSOqYXcAOqIJ0UuH63pHG9THW+EcIwKzZAYlPxFtJI0m9AKpEX93X9PkUZn+GtTrm oo/gB8ThYGQ1WLK4CnJAMrJioRQmov0i7lj0r9n48XdOyQFhtQUE+Op5V5AZFd3pB4If yU5Q== 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=SPuyZpiaeMW7v65IWK0vJIfRpGGit+CNrEvkfOmMaMI=; b=AnI8hhg6BSzPg0zwdwJwek7EMQJ1y7oCeceSz+OB7hZjnIT6q/dUEXPscJRuLDCKPJ 6USrwEpLNQRVlD9YgwGDuhaoes+2kgF0XZnvdd94oyJlosKwsnGCmKBHXmlmkCCwI2KQ CdAJvNSBvp+D4/a8YNq6+1RUnWmircijQprVSLsbjnsoPu4J4RlFixBcoF/FQzcwpmH7 0KXX3zmuIV3CdKJrIsEGhdaKetn9YQ3v89BfC5CzEFmquGAJRbVxo+HFi6IlYHE6Vo3b Fuv0fRTT/870sNdGIZv7a9J5sXfwSZsffVbrMh9xyzmuJkWzcYDbdIdT282eWExcq5mr o2gg== X-Gm-Message-State: AOAM531D8OzsE25kZKJdj6ABIMGl7JGF7/pRCbnHGV1RXLZ9nWmmH0BE pO4oaz37ckbMw1dHptLl6BgiL9sknxwR4NKZ4as= X-Received: by 2002:a63:ff52:: with SMTP id s18mr25908886pgk.203.1593074673817; Thu, 25 Jun 2020 01:44:33 -0700 (PDT) MIME-Version: 1.0 References: <20200623040107.22270-1-warthog618@gmail.com> <20200623040107.22270-11-warthog618@gmail.com> <20200624155714.GB8622@sol> <20200624225803.GA3600@sol> In-Reply-To: <20200624225803.GA3600@sol> From: Andy Shevchenko Date: Thu, 25 Jun 2020 11:44:21 +0300 Message-ID: Subject: Re: [PATCH 10/22] gpiolib: cdev: fix minor race in GET_LINEINFO_WATCH To: Kent Gibson Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 25, 2020 at 1:58 AM Kent Gibson wrote: > On Wed, Jun 24, 2020 at 11:57:14PM +0800, Kent Gibson wrote: > > On Wed, Jun 24, 2020 at 05:46:33PM +0300, Andy Shevchenko wrote: > > > On Tue, Jun 23, 2020 at 7:03 AM Kent Gibson wrote: ... > > > I stumbled over this myself, but... > > > > > > > - if (test_bit(hwgpio, gcdev->watched_lines)) > > > > + if (test_and_set_bit(hwgpio, gcdev->watched_lines)) > > > > return -EBUSY; > > > > > > > > gpio_desc_to_lineinfo(desc, &lineinfo); > > > > @@ -897,7 +897,6 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > > > if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) > > > > return -EFAULT; > > > > > > > > - set_bit(hwgpio, gcdev->watched_lines); > > > > return 0; > > > > > > ...I think it's not an equivalent despite races involved. If you set > > > bit and return error code, you will have the wrong state. > Perhaps you are referring to the case where the copy_to_user fails? Yes. > To be honest I considered that to be so unlikely that I ignored it. > Is there a relevant failure mode that I'm missing? The traditional question for such cases is "what can possibly go wrong?" I wouldn't underestimate the probability of failure. -- With Best Regards, Andy Shevchenko