From patchwork Fri Oct 13 23:35:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10006139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86E956037E for ; Fri, 13 Oct 2017 23:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 778E329009 for ; Fri, 13 Oct 2017 23:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C62829191; Fri, 13 Oct 2017 23:36:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E263729009 for ; Fri, 13 Oct 2017 23:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753270AbdJMXgR (ORCPT ); Fri, 13 Oct 2017 19:36:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:47485 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752468AbdJMXgP (ORCPT ); Fri, 13 Oct 2017 19:36:15 -0400 Received: by mail-pf0-f196.google.com with SMTP id z11so11520307pfk.4 for ; Fri, 13 Oct 2017 16:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4bxWwHLD1iUvYPnmiOhM/1gzDd0VOzD6lGyg9akfCk0=; b=Pl2c3tihP+ChHd+jzpw1EwKRMTuPxE/X2t47IHAFqTq3FVJRtPWWCHKSsyUYMrPZJ+ KocChYII9fD9CQtjN0FB/5ig8O/R/e44pMyRs09Te6hmxmeeG5J3ETOGHIXu1jOagpMt PyHJVaRljwO4YF3vjlvfUJJnU9JQhfyvLJWcqwrj+mi5XHnrBuo7w1SNY20COdZkmDEH 3Hh7f66iL7/q/zUFSar2WAKc1LaZ/DUFsw++saPWtF2OBvFSm7s9fm/TimzGeHz+j15g dudAZdWxwtMQGHJF+Fm4/Ml90g3koRmCDNpeQFQc2o0UInyf+vUkwRYGqJF1B77qgk17 TnOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4bxWwHLD1iUvYPnmiOhM/1gzDd0VOzD6lGyg9akfCk0=; b=c7wJgN0Pq3AdYu5rvfLXt8sLtER2oOYl/md/bTMRb5DkyqOuwtvbjeGBwxRLI030bA PAwPxJgO/sYEqUs2SSqWoWKNPq3AAtMYANNMsnF414416ixWwa6PA4l9iFZ+h3BeZr/V wKImmF3e0nPX5sRl4UfRbuw4byaIFdITYzk9GVZNf4KPRhnTn3uX/eEhRRkYv2w2KpeW hfqVO1B4LRppi+bDe2TvOblxnIlwq/iLVlbRtgFMKHUQM4PrC63oPR6JTQCY40iN8Bf4 1gtK4tcLttYvhaxyyxFd87ObsBPWnT94LHYbk1vz4yvmn7vL5BLZTo1zj/WVndSbkFO8 oytw== X-Gm-Message-State: AMCzsaVYlKUg5WikjbKB7/aqhuftbu2k/2DPt1EsTCW5YycuvemmfV0Y h+AXv0o3RpGh77KwXrkjShmk1A== X-Google-Smtp-Source: AOwi7QDHFaYqymRmz943GxaDbvq6o31aN6drwRIbB8EaFZOphPB9ntohkyVQHxQ71ldZQDnNrwn1Og== X-Received: by 10.159.207.134 with SMTP id z6mr2673245plo.258.1507937774845; Fri, 13 Oct 2017 16:36:14 -0700 (PDT) Received: from localhost.localdomain (68-189-67-104.dhcp.prtv.ca.charter.com. [68.189.67.104]) by smtp.gmail.com with ESMTPSA id 74sm4950718pft.184.2017.10.13.16.36.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 16:36:14 -0700 (PDT) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: axboe@fb.com, Liang Chen Subject: [PATCH 13/15] bcache: safeguard a dangerous addressing in closure_queue Date: Fri, 13 Oct 2017 16:35:40 -0700 Message-Id: <20171013233542.20938-14-mlyle@lyle.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171013233542.20938-1-mlyle@lyle.org> References: <20171013233542.20938-1-mlyle@lyle.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Liang Chen The use of the union reduces the size of closure struct by taking advantage of the current size of its members. The offset of func in work_struct equals the size of the first three members, so that work.work_func will just reference the forth member - fn. This is smart but dangerous. It can be broken if work_struct or the other structs get changed, and can be a bit difficult to debug. Signed-off-by: Liang Chen Reviewed-by: Michael Lyle --- drivers/md/bcache/closure.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h index 295b7e43f92c..00fb314cce57 100644 --- a/drivers/md/bcache/closure.h +++ b/drivers/md/bcache/closure.h @@ -251,6 +251,12 @@ static inline void set_closure_fn(struct closure *cl, closure_fn *fn, static inline void closure_queue(struct closure *cl) { struct workqueue_struct *wq = cl->wq; + /** + * Changes made to closure, work_struct, or a couple of other structs + * may cause work.func not pointing to the right location. + */ + BUILD_BUG_ON(offsetof(struct closure, fn) + != offsetof(struct work_struct, func)); if (wq) { INIT_WORK(&cl->work, cl->work.func); BUG_ON(!queue_work(wq, &cl->work));