Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5119414ima; Tue, 5 Feb 2019 06:42:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ1tPUDb73xjy78imq9DdBTMt2tUZhbSR30Mj0VSphpWASU+bUA91cvWZ5LfjfJdnnRzuGB X-Received: by 2002:a63:184a:: with SMTP id 10mr4800668pgy.81.1549377732698; Tue, 05 Feb 2019 06:42:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549377732; cv=none; d=google.com; s=arc-20160816; b=OGTfwoeAJaK2TGpi15ik3Xt+9gpInkySx/JvHfYdGk3M9QGhVN+jmVH6oAkgUVCJAv JKbBtVLgCAKmUCGUiQvYg/NeMfbzUbsM9aGdeAST3D3chl1WYY4/PfUjM4IOM6f3YMYW B/VubdZlRC1y+u3yTApD5pxDwarP3X4eoklDVhUrqH63+m0uL5JAjdvR9aQUB7ZNYYiD ZZqu4BB4IdUlsPr4Vu88atyqPTIiT5+iytIzYOmXdGWCNpweSYBudHB7ofxpKj+t0reX jGsYVsqW7BjriNK+sJZHLD/0DOlAJGTy/oXbR/iThA6eSoS/P927AscBJzGOF0hRGqKv zHXQ== 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=1glb51HkHjX7PiXJmxshImHAV6rzwB8ggE3jjrWteQc=; b=zf0m7LZT/1lN7pM4pqr62y/Z2tiJN3Hfkd8x4bwpnv7fh6m+kRoY93Wv5Pud/7j1aF 7XFTqd4u7mCQVpT+qbL1Yotx8UCWLGCPMS6+FuRPdruabzSsbcYb4ZZ6C8Dl1CHoaQtB WbhX3iaS+h4oiDRKaTixYU94PEnXObg19SwZkEqqNHfasJBAvk1rhjykuF4D+6ezioCk /I8k5hMGKljLbxp41frVjAGIcxhVFbufIKAtNrZ0qjaEbx0KbXOV8BFOWnXP4fHuXDwk YDTvt97974QdGOuKzW8x3oGvn1Myxkfkrza+sxOLfj8iE/owi2TFWGF9mNbYI/mZLdp+ DZeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f7kZcmY4; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si573269pgq.105.2019.02.05.06.41.56; Tue, 05 Feb 2019 06:42:12 -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=@gmail.com header.s=20161025 header.b=f7kZcmY4; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728659AbfBEO2B (ORCPT + 99 others); Tue, 5 Feb 2019 09:28:01 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:42804 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726887AbfBEO2B (ORCPT ); Tue, 5 Feb 2019 09:28:01 -0500 Received: by mail-ot1-f68.google.com with SMTP id v23so5895544otk.9 for ; Tue, 05 Feb 2019 06:28:00 -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=1glb51HkHjX7PiXJmxshImHAV6rzwB8ggE3jjrWteQc=; b=f7kZcmY4BsDLvaPwtw0KqBHCaPEP6oflCTVjYme6yCsGU2018Ts41Iwa5tjFrXvD1+ bIVpi7f+7IV4tiNU81+XPbQ/6ADWY8vOdWHb2HmtRtaC4X2TuWpZE1cBRW+UB+CF97UJ I+d32FNbawNUr2r+PMLTDw7+JEnCr3lvOAUcEs2YnlRYj7ImvUzFp+OqAFxP90c9FlX6 niv/OQtOPEH5dfxJhfTHR8gCbqWmAfoN5Tvl3cVQXZTdteu85q3RWKE8BQgl1Jtxlybw 0eyxWMID8dAhqMx2vRvFVUJqszHVOowUroY46L4k4vOhYWoDqMxoaLvnXT7HqxjYZrfH xrgA== 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=1glb51HkHjX7PiXJmxshImHAV6rzwB8ggE3jjrWteQc=; b=qQpCSc4xZvO4fTiSPJHJVdQnq8sSk2pPdC6t+BXOZR7QXGoFKF/jBHMRuVlMwVSy6N rcYDykw3RZxeUQpsVktwsEEnUWCWi0bY6quTSBz1wuoTd4aKoAtUViYtAH9l+lgG8gIm oeH3tve7wkxKBNJCFPtFF1dpO7TbLdHixWu7RXR1yaJNlBOR3mawCzw5+XpDsV5nWuMy ufbFG6W6dYjS6x38LL1wsx0+7XXhuUIW/Gu74fvHE8HRLQIQ5IAAq0bhMDwg3ElTeE9E 9Tl1TCriOXzQj8nnIMcqdSRtyAOhrjj65f23ZraOo3XSrb5nNQ2k20dWXeq6ZCfV0gqN /sMg== X-Gm-Message-State: AHQUAubFyaoakJbuN9OwnfnLa5EjptA2PDuF9W9dJiAHTEus8+YoCEvJ 2sDCGrucigouSIXQ6yuXIWQnOwNnSpfAH7EMoOc= X-Received: by 2002:a9d:d21:: with SMTP id 30mr2795512oti.245.1549376880334; Tue, 05 Feb 2019 06:28:00 -0800 (PST) MIME-Version: 1.0 References: <20190204220952.30761-1-TheSven73@googlemail.com> <20190204220952.30761-3-TheSven73@googlemail.com> <20190205082727.GB118684@dtor-ws> In-Reply-To: <20190205082727.GB118684@dtor-ws> From: Sven Van Asbroeck Date: Tue, 5 Feb 2019 09:27:49 -0500 Message-ID: Subject: Re: [RFC v1 2/3] max17042_battery: fix potential user-after-free on module unload To: Dmitry Torokhov Cc: Tejun Heo , Lai Jiangshan , Linux Kernel Mailing List , Sebastian Reichel , Kees Cook 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 Tue, Feb 5, 2019 at 3:27 AM Dmitry Torokhov wrote: > > Are there many more instances of this? Unfortunately I think so. A simple grep brings up a couple of candidates, but I'm sure there are more: drivers/regulator/arizona-micsupp.c drivers/nfc/port100.c drivers/power/supply/max14656_charger_detector.c drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c > I am unsure if we need > devm_init_work() when we can easily do the same in remove() call. The devm_init_work() suggestion only addresses the problem for those modules that use devm_. The others will need fixes in remove(). But this is not as elegant and error-proof as using devm_init_work(). For example, take port100.c's disconnect function. It starts deallocating resources, but the cmd_complete_work (scheduled by urb completion) may still be in progress, and touch these resources after free. At least, I _think_ that is the case. I'm not familiar enough with this driver to be 100% sure, but it sounds likely. static void port100_disconnect(struct usb_interface *interface) { struct port100 *dev; dev = usb_get_intfdata(interface); usb_set_intfdata(interface, NULL); nfc_digital_unregister_device(dev->nfc_digital_dev); nfc_digital_free_device(dev->nfc_digital_dev); usb_kill_urb(dev->in_urb); usb_kill_urb(dev->out_urb); usb_free_urb(dev->in_urb); usb_free_urb(dev->out_urb); usb_put_dev(dev->udev); kfree(dev->cmd); nfc_info(&interface->dev, "Sony Port-100 NFC device disconnected\n"); }