Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4382949imb; Wed, 6 Mar 2019 12:03:33 -0800 (PST) X-Google-Smtp-Source: APXvYqw0uTHZezFaOjiQQerv6PmgE2B/pFzn1k3ZaF2n8G8zDJE4CQFfageDTPp+4nZ4f2DVnvuZ X-Received: by 2002:a62:1f5d:: with SMTP id f90mr8900055pff.104.1551902613303; Wed, 06 Mar 2019 12:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551902613; cv=none; d=google.com; s=arc-20160816; b=Y9G8crOA/E/yoSWPy6e4sugXgs4kGw8BpdpqDNkZmHE3N/YrxY+GIxil3oci0vT8xN Kw70wsHFzpFi/cvTGAjRdJnpK3UDJtOtzICHlHuoKCTBFwsUemEZrgb6sVyLuvKzddqG Zx4d7Sp+eAEPNM7ztQCXQWicsmdlsGsArQKea5WRPFazbCT19722QUOoId4AFTDHJK6V 3v4zp7YynfPnH2nJzqdSbaOAFj9KuVyO0/72AdVeS2PtfBxlr/H5GwR7higCqfKCOQ/G CbI06yVug9n/JbavJVmDPby8P9wkO0/Csrjrx66yaWb1qdqoREUEzJvzxDIItZKqiU9O rNLA== 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=fpuLNU2Kuec6CYG2jcXVc/5+sYpINIjuPXPul/4MwGI=; b=hUFyxJL7Pi+ShFs2PkZcq2KTJ1djghDj7twrLOogWW2gONgayKAbhlqnk3VJn12dwm IHqovVTVZ1TpSczXcka2kB/hbAUfLaTDWu7QMN0NC5nVV9DNgxBI3HHFmNQSczpjZ7Mh 2dVyZg01voHIZb9tV3si9Eq//5b60sbXkXiSAuBzPkYkkVBQ7zVnUtfKpCsaqhoAIxta +tlPUFGgZWHLORGR0LbVkeRT0iWJnPWTXHecZ2ljrzvtD7458NjsLbg5EkolFcigwyno cxQHJjAX75aqGINPKOY+T3Sb1SX/8pelmHlA2oRCMxgREF1W+ERGxqpn/YD/i4qqVeMO gwMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=un5XrjC5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 145si2015478pga.532.2019.03.06.12.03.14; Wed, 06 Mar 2019 12:03:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=un5XrjC5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730321AbfCFR2p (ORCPT + 99 others); Wed, 6 Mar 2019 12:28:45 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46815 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726409AbfCFR2o (ORCPT ); Wed, 6 Mar 2019 12:28:44 -0500 Received: by mail-yw1-f66.google.com with SMTP id n12so10625676ywn.13 for ; Wed, 06 Mar 2019 09:28:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fpuLNU2Kuec6CYG2jcXVc/5+sYpINIjuPXPul/4MwGI=; b=un5XrjC5oPNUb99gN5qDnHU/FiBgsnQ5briB0mcxtM/Ob+T4Q0W91XSjLWmCXFATIW FqMAs5hKrInYdxgSJh+zyAJbyGz2HObY1HdBT5Def5cHuAhtUrEBRM+W14zqu5Kf75Ga Ff/dzd5jaGahn+1Mj6LZEfyra02COr+fS+5atSq3ZFQLx9JcD2lPabIFtnGDVmn05963 nxWvvI68JH6DGKRsUgQQ9IF5sFW88+21vP5ydRRBlOJmMjBVibD9ARsM3IdDfVybrIEw ThQ4qaqzLigZl9y7//GhCJSR9kIRNoo68tP7Zwp+MytflJJzk1ESku1LtbfERnjQSyhs N2ow== 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=fpuLNU2Kuec6CYG2jcXVc/5+sYpINIjuPXPul/4MwGI=; b=Z3HE2uB9FM5Mh0aujmMhPGsSTZUqttjAww21b5Z1l2HVmHBs3fyNSLA5kKkaXNanCF BFiU44oZDAJ/dxuqmE0KTzX/qQsIyrIFzgs9ORxPDSib+Fz25W1EryEEHrrHBRnh41m+ zbBF1ZZ1abjzZ4x9XE1KgIPN5HifAXZurUVvu4UzcdCoeiek/hERLZMxYDjE5t1Lfb6m ulh3k+DJ8v2KmlkuSu0pNp207jg6NBp7WZm/+PLjdQvYrgxGT0ob1EhDxW1G1FKwy/vV GVT+D07Q32hBfXBCuGa6i8WprX3IfnyPmkDIoSlZuLJurVDgDsr9+JF9sCY/yQttd9AM e5EA== X-Gm-Message-State: APjAAAW1T3RFeOu9YaMkBpCvLAdHY5abVYiN87mB+4OKh+vqBCyjwiF4 cidUQuNVbIeNsCJ3cwaDpQKFKWNbwqGoHkmaLHYsDA== X-Received: by 2002:a81:5987:: with SMTP id n129mr6417958ywb.95.1551893323782; Wed, 06 Mar 2019 09:28:43 -0800 (PST) MIME-Version: 1.0 References: <20190304153714.GD13452@kadam> In-Reply-To: <20190304153714.GD13452@kadam> From: Anders Roxell Date: Wed, 6 Mar 2019 18:28:33 +0100 Message-ID: Subject: Re: BUG: KASAN: i2c dev use after free To: Dan Carpenter Cc: erico.nunes@datacom.ind.br, wsa@the-dreams.de, Linux Kernel Mailing List 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 Mon, 4 Mar 2019 at 16:37, Dan Carpenter wrote: > > I wasn't trying to fix anything so complicated as this, it was a > more obvious use after free. It does feel intuitively that we should > call device_destroy() before the cdev_del() so that it's in the reverse > order from how it was allocated but I don't see any reason to think > that will make a difference. No that didn't make any difference... =/ > > --- > drivers/i2c/i2c-dev.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c > index 3f7b9af11137..7e85e2cf26c1 100644 > --- a/drivers/i2c/i2c-dev.c > +++ b/drivers/i2c/i2c-dev.c > @@ -687,9 +687,9 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy) > if (!i2c_dev) /* attach_adapter must have failed */ > return 0; > > + device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); > cdev_del(&i2c_dev->cdev); > put_i2c_dev(i2c_dev); > - device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); > > pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); > return 0; > -- > 2.17.1 >